can someone explain to me why the result is 8 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can someone explain to me why the result is 8 ?

x = 1 while (x <= 5): x += x print(x) 8

18th Mar 2022, 11:01 AM
Game0ver
Game0ver - avatar
3 Answers
+ 3
Game0ver x += x means x = 2 * x So on x = 1, x = 2 On x = 2, x = 2 * 2 = 4 On x = 4, x = 2 * 4 = 8 Now 8 <= 5 false so x = 8
18th Mar 2022, 1:09 PM
A͢J
A͢J - avatar
+ 2
Try to put x +=1
18th Mar 2022, 11:39 AM
Gonçalo Vicente
0
thank you so much
18th Mar 2022, 6:06 PM
Game0ver
Game0ver - avatar