Search code examples
pythonpython-3.xindentationpython-idle

Problems with indentation on Python


I'm having problems with my conditionals. I can declare the if but after I press the Enter in the next line, in which I will declare the else, does not have the correct indentation. The conditional else is on the same level as the command print. I fix this using the backspace, so the else stays at the same level as if, but after I press the Enter I get the message: "SyntaxError: unindent does not match any outer indentation level". Follow the print of the result in my editor here.

escada = 'sim'

if escada == 'sim':

    print('Subir na escada e trocar a lâmpada')

else:

    print('Pegue uma cadeira')

Solution

  • Python IDLE has pool view.

    Your case

    >>> escada = "sim"
    >>> if escada == 'sim':
        print('subir')
        else:
    ^^^^ # should be removed
    IndentationError: unindent does not match any outer indentation level
    

    Fixed

    >>> escada = "sim"
    >>> if escada == 'sim':
        print('subir')
    else:
        print('else...')
    
    subir