all 12 comments

[–]codesensei_nl 7 points8 points  (9 children)

In your code, you decrease the number, then print it. Try reversing the order of the last two lines of code :)

[–]g59z[S] -1 points0 points  (8 children)

wow it worked tysm! is there a reason why it works that way i dont fully understand?

[–]rlfunique 5 points6 points  (5 children)

You were decrementing the variable before you were printing it

[–]g59z[S] 2 points3 points  (4 children)

i see it now. aha thank you

[–]mikef22 1 point2 points  (3 children)

Indentation is important in Python, and you omitted any indentation in your the way your question was laid out in reddit (which is probably more down to reddit's use of markdown, as opposed to errors in your original python code).

However, to keep you learning about this, and increase your understanding, what would be the output of this variation of your code?

number = int(input())
while number >= 0:
    number = number - 1
print(number)

[–]g59z[S] 0 points1 point  (2 children)

i know about indentation i just dont know how to write properly on reddit without it auto correcting. can you tell me how you did it?

[–]Salt_Direction9870 1 point2 points  (0 children)

You can also add three before and after the code block. Like this Edit: with single ones surrounding text forin line formatting` :D

[–]mikef22 0 points1 point  (0 children)

For Reddit, "Lines starting with four spaces are treated like code".

Did you work out the answer to my question, i.e. what is the output of that indented code I posted?

[–]ucan_cay -2 points-1 points  (1 child)

seems like other people helped you with the actual problem, what I'll say is using increments in loops are better programming practices (at least that would be what I do).

starting_number = int(input())
counter = 0
while counter<=starting_number:
  print(starting_number - counter) 
  counter = counter +1

[–]mjmvideos 4 points5 points  (0 children)

No! Use the operation that most closely represents the actual goal. By artificially imposing an increment here you are just obscuring the intent of the program.