0

[SOLVED] Can someone please explain to me why the output of following code is 55?

sum = 0 x = 10 while x > 0: sum += x x -= 1 print(sum)

7th Dec 2022, 5:11 AM
Haru
Haru - avatar
1 Respuesta
+ 6
In each iteration of the while loop, a number is added to sum, and the number is decremented by 1 until it reaches 0. So the result is sum = 10+9+8+7+6+5+4+3+2+1
7th Dec 2022, 5:26 AM
Tibor Santa
Tibor Santa - avatar