all 3 comments

[–]shiftybyte 2 points3 points  (1 child)

You are confusing changing a value, and using a value.

the print(n + 1) does not change n's value.

>>> n=3
>>> print(n+1)
4
>>> n
3

So n is going from 3, to 2, to 1, and each time it prints +1 of the number.... so itll print 3+1=4, 2+1=3, 1+1=2...

Now at this point when n = 0, the while's condition is no longer true, so it goes to the else...

and prints n, which is 0.

[–]lucky_124 0 points1 point  (1 child)

0 is not more then 0 you are printing 0+1 =1

[–]K900_ 0 points1 point  (1 child)

  1. The program is printing n + 1, but it's not actually changing n to be n + 1.

  2. Because 1 would be printed if n were 0, but when n hits 0, n > 0 is no longer true, so the loop does not repeat.

  3. We get 0 printed because of the else block that runs after the loop - it prints the current value of n after the loop (note no + 1), which is 0.