+ 5
# take the number as input number = int(input()) while number <= 0: print(number) number = number - 1
How to solve the indent error from this code. I couldn't solve this in python
7 Answers
+ 2
keep in mind that indentation in python is very important because it tells the interpreter when the block of code has starts and when it ends.
whenever it encounters a newline after indentation it means block is ended.
you must always use spaces for indentation instead of tabs.
and it should be consistent throughout your program.
According to convention you must use 4 spaces to indent your code.
+ 3
I think you should use >= 0
cause if you give <= 0
this means user should enter -ve numbers
but I see you are trying to decrease the number so you expect +ve input
hence use
>=0 instead of <=0
+ 1
arooj amina Delete all the indents and then reindent again with equal number of spaces.
+ 1
While Ratnapal Shende's advice is good, there's no such requirement to always use spaces for indentation. Just be consistent, and use either only spaces or only tabs.
+ 1
arooj amina The problem with your code is not the indentation, if you copy it into Code Playground, you'll see it works just fine, with no error.
But the problem is with the logic. It either don't output anything or goes into an infinite loop. As Snehil pointed out you messed with the comparison operator.
+ 1
I solved it
Snehil your answer solve this error
Ratnapal Shende your suggestions also helpful.. thanks everyone Евгений u also good 1
0
Just remove the indention on the last line.