# take the number as input number = int(input()) while number <= 0: print(number) number = number - 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

30th May 2023, 6:45 PM
Arooj Amina
Arooj Amina - avatar
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.
30th May 2023, 8:36 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 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
30th May 2023, 7:04 PM
I am offline
I am offline - avatar
+ 1
arooj amina Delete all the indents and then reindent again with equal number of spaces.
30th May 2023, 8:02 PM
Евгений
Евгений - avatar
+ 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.
30th May 2023, 9:16 PM
Евгений
Евгений - avatar
+ 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.
30th May 2023, 9:49 PM
Евгений
Евгений - avatar
+ 1
I solved it Snehil your answer solve this error Ratnapal Shende your suggestions also helpful.. thanks everyone Евгений u also good 1
31st May 2023, 1:10 AM
Arooj Amina
Arooj Amina - avatar
0
Just remove the indention on the last line.
1st Jun 2023, 11:56 AM
MattMad
MattMad - avatar