IndentationError: command line (Win10)

In the command line, I am using the following nested in a while-loop, so both the ‘if’ and ‘else’ are indented 1 tab space:

if answer == test:
        remaining = points - elapsed
        print('You have ', round(remaining), 'points remaining.')

but am getting this:

  File "<stdin>", line 13
IndentationError: unindent does not match any outer indentation level

Chances are you have a leading space in front of that else: If you can, make your space chars visible so you can see them. Io had a post about that in the forum just now for VS Code.

1 Like

I have encountered the same problem in the past, Zed, and in my situation it is not due to leading spaces. I have solved the problem by using the space bar to insert the correct number of spaces instead of using the tab key.

Is this inside your text editor or just on the command line? In the text editor, your tab key should totally input for spaces when you hit the. if not then you need to find the setting in your text editor to tell it to use spaces only. Tell me what textured are you using and I’ll find the solution for you if you can’t.

For me it was strictly command line for this issue. Never an issue in notepad++. Have moved on but I recall with this issue I exited python and ran “clear” in command line. Then went back into python and got the same issue (tho I may have used the up arrow to repopulate lines, idk.) When troubleshooting this, I hit backspace to explicitly clear the entire line, then tabbed across, and still got the error.

Here is a different issue with command line that just occurred:

>>> if i in range(1,11):
...     if i == 5:
...             continue
...     print(i)
  File "<stdin>", line 3
SyntaxError: 'continue' not properly in loop


>>> for i in range(1,11):
...     if i == 5:
...             continue
...     print(i)

…which printed out fine. The only thing I did was go into command line properties and root around for a bit, changing and saving nothing. Then went back and tried it again. shrug

Ah yes, continue is only for loops. It should also work with while loops too. Inside an if it doesn’t really make much sense.

1 Like

In the first example there is an additional space before the second “if”. Perhaps the indentation is not correct…

See how it is lined up in comparison with the second trial? The second ‘if’ starts under the underscore (i.e., _ ) I used in the first trial, but under the letter i in the second trial

if i_in range(1,11):


if i in range(1,11):

1 Like

This situation was in Notebook ++ but it is now fixed. Thanks!