1
>>> x = 5
>>> y = 3
>>> if x == y:
        print("Yes")
    else:

SyntaxError: unindent does not match any outer indentation level
>>> 

I keep having this problem. I am new into Python but I want to learn it seriously and I am struggling with this error. I made research about indentation and tried to review my few lines of code but with no succes. I cannot understand why it keeps appearing as I tried not to mix tabs and spaces. Thanks in advance for help! (I am currently running Python 3.6.4)

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
  • 2
    1) Are you adding spaces before the `else:`? 2) shouldn't there be something (a line) after the `else:`? – user2864740 Feb 14 '18 at 18:35
  • I think your problem is stemming from there being no code in the `else:` block. If you don't need anything else to happen after the `if` executes then simply don't include the `else:`. – A Magoon Feb 14 '18 at 18:49
  • Well there is a red long line after the else caused by the error. And I want to put something in the else block but I can't because I have to press ENTER and this causes the error to pop up. Pretty frustrating :/ –  Feb 15 '18 at 16:34
  • The `>>>` are **not part of the code**, so deciding how the code should line up should *not take them into account*. The plain REPL editor at the terminal should be automatically showing `...` before lines of a multi-line statement to match the `>>>` and make everything visually line up. – Karl Knechtel Jul 14 '23 at 19:46

4 Answers4

0

add or print some thing in else block. It will resolve your issue.

x = 5
y = 3
if x == y:
   print("Yes")
else:
   print("No")
0

Try the below code without the else block and see if it still gives you the same error.

x = 5
y = 3
if x == y:
    print("Yes")
A Magoon
  • 1,180
  • 2
  • 13
  • 21
  • Yeah you are right the code runs well without the ELSE but I can't understand why it goes wrong if I put it there. –  Feb 15 '18 at 16:36
  • Because `else` implies that there is additional code that needs to be executed. It expects something to be there so it throws an error when it can't execute anything and gets stuck within the `else` block. – A Magoon Feb 15 '18 at 16:49
0

Ok i am also using a Python SoloLearn app and tried to write the same code in the Code Playground and it works just fine. I also did use my fathers laptop and looks ok there too... (He is using 3.3... or similar). So I can only say that maybe its some kind of weird bug occuring on my laptop or on 3.6.4. Anyway thank you all for answers and fast reply. I just wanted to be sure its not my bad and now I'm pretty sure its not :))

0

First I try:

>>> a=30
>>> if(a>100):
        print(">100")
    else:

SyntaxError: unindent does not match any outer indentation level
>>>

Then:

>>> a=30
>>> if (a>100):
        print("+100")
else:
        print("-100")


-100
>>> 

The editor use tab, so after the end of a block and press 'Enter', it add automaticly an indentation. Then just press 'Backspace' (or 'Tab') to align to the correct block.

You notice that the first 'else:' is align to the start of line.

Enjoy