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