Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Indentation error while using IDLE and if - else block, works fine on command line [duplicate]

Tags:

python

I get the following indentation error

>>> number = 35
>>> if number == 35:
        print 'true'
    else:

  File "<pyshell#130>", line 3
    else:

^
IndentationError: unindent does not match any outer indentation level
>>> 

This happens only on IDLE and not on command line. I am using Python 2.6.4 on Windows XP. I have searched online, but not been able to find any answer as to why I get this error. Thankful for any help.

And to add - The code may not look properly indented when copied and pasted. But it was properly indented on the IDLE interface.

like image 246
Sumod Avatar asked Apr 29 '26 16:04

Sumod


1 Answers

>>> number = 35
>>> if number == 35:
...     print 'true'
... else:
...     print 'false'
... 
true
>>>

indent your code properly and manually

like image 103
avasal Avatar answered May 01 '26 04:05

avasal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!