+ 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)

6th Sep 2017, 6:46 AM
Anil/Anant/1949Nov
Anil/Anant/1949Nov - avatar
14 Respostas
+ 4
good journey in py anything, i will be glad to help !
6th Sep 2017, 7:21 AM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 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
6th Sep 2017, 8:31 AM
👑 Prometheus 🇾🇬
👑 Prometheus 🇾🇬 - avatar
+ 3
y=7 #5 is the number of times to repeat for i in range(5): y*=2
6th Sep 2017, 6:48 AM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 3
I dun get your question
8th Sep 2017, 11:21 AM
👑 Prometheus 🇾🇬
👑 Prometheus 🇾🇬 - avatar
+ 2
just give me an exact question to solve i think i might not have understood tge question
6th Sep 2017, 8:19 AM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 1
Thank you Abdur
6th Sep 2017, 7:14 AM
Anil/Anant/1949Nov
Anil/Anant/1949Nov - avatar
+ 1
y=7 x=y*2**5 means y×2×2×2×2×2×2
6th Sep 2017, 8:21 AM
sayan chandra
sayan chandra - avatar
+ 1
y=7 for i in range(5) : y=y*2
6th Sep 2017, 8:23 AM
sayan chandra
sayan chandra - avatar
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.
6th Sep 2017, 7:41 AM
Anil/Anant/1949Nov
Anil/Anant/1949Nov - avatar
0
what u want to do... be specific
6th Sep 2017, 8:11 AM
sayan chandra
sayan chandra - avatar
0
y=7 y=y*2 y=y*2 and so on 5 times so y =224
6th Sep 2017, 8:15 AM
Anil/Anant/1949Nov
Anil/Anant/1949Nov - avatar
0
thats another... in this for loop y is changing.. remember
6th Sep 2017, 8:24 AM
sayan chandra
sayan chandra - avatar
0
no y is not changing It is like going to line 10 every time in BASIC where y was 7
8th Sep 2017, 11:19 AM
Anil/Anant/1949Nov
Anil/Anant/1949Nov - avatar
- 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.
8th Sep 2017, 11:25 AM
Anil/Anant/1949Nov
Anil/Anant/1949Nov - avatar