+ 2
In Python how do i repeat an operation eg y=7 2*y...2*y...
like in basic we write go to 10(ie line 10)
14 Antworten
+ 4
good journey in py anything, i will be glad to help !
+ 4
For repetition purposes, we use loops.
These are 2 main loops we use:
for and while
for (variable) in (something):execute command
the range(...) is an object that returns numbers in that range.
range(x)-->numbers from 0 to x-1
range(y,x)-->numbers from y to x-1
range(y,x,z)-->numbers from y to x-1 insteps of z.
while (condition is true): execute
If the condition eventually doesn't turn false, it becomes a loop that runs forever.
This should help you
+ 3
y=7
#5 is the number of times to repeat
for i in range(5):
y*=2
+ 3
I dun get your question
+ 2
just give me an exact question to solve
i think i might not have understood tge question
+ 1
Thank you Abdur
+ 1
y=7
x=y*2**5
means y×2×2×2×2×2×2
+ 1
y=7
for i in range(5) :
y=y*2
0
Abdur
I just tried two programs in py to "repeat" multiplying two numbers 5 times over.
but multiplication was not done 5 times.
I must have made some mistake.
Can you please find mistake so we can get correct solution.
0
what u want to do...
be specific
0
y=7
y=y*2
y=y*2
and so on 5 times
so y =224
0
thats another...
in this for loop y is changing..
remember
0
no y is not changing
It is like going to line 10 every time in BASIC
where y was 7
- 1
multiply y by 2 endless times till loop is terminated or program stopped
like 1 baby is added every 2 seconds in India unless you exit viewing program result.