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)

21st Jun 2021, 5:56 PM
Myo Min Htet Aung
Myo Min Htet Aung - avatar
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
21st Jun 2021, 6:21 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 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.
21st Jun 2021, 6:18 PM
Angela
Angela - avatar