0
I don't understand it! Can someone explain me?
Why this codes output 10? a = 1 while True: a = (a+1)*2 if a >7: break print(a)
2 Respuestas
+ 3
a=1
goes in the loop
a =(a+1)*2=(1+1)*2=4
now a=4
again it loops.
a =(a+1)*2=(4+1)*2=10
now a=10
since a>7 it breaks the loop and print the value of a which is now 10
+ 1
After 1st loop
a =(1+1)*2
a = 4
Then second loop
a = 4 (from the 1st loop)
a =(4+1)*2
a = 10
10 > 7, while loop breaks and output is 10.