0

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')
Vanilla
  • 51
  • 1
  • 3
  • 9
Alineat
  • 833
  • 6
  • 9
  • What editor is that? Indentation is the number of spaces (or tabs) used, which usually (and should) correspond to vertical alignment, but in your crappy editor, it doesn't appear to be the case. – Arafangion Aug 30 '17 at 01:29
  • As Arafangion suggests, Python, because of its significant whitespace, genuinely requires that your editor and yourself be on the same page about many things, but most importantly, constantly, about which leading characters are being used for whitespace, how many of them are being used, and whether they're consistently being used. – Jan Kyu Peblik Aug 30 '17 at 01:30
  • @Arafangion , it's IDLE. – Alineat Aug 30 '17 at 15:04

3 Answers3

1

You missed the right indentation inside if and else.

To denote indentation, you could either:

  1. Use four spaces (' '), recommended by PEP8, see: https://www.python.org/dev/peps/pep-0008/
  2. or a Tab (' ').

When running Python from the command line, as shown in your screenshot, you should see ... indicating that Python expects an indentation. You should see something like this:

>>> escada = 'sim'
>>> if escada == 'sim':
...     print('subir')
... else:
...     pass
... 
subir
>>>
joegalaxian
  • 350
  • 1
  • 7
0

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
Ho0ony
  • 158
  • 11
0

As indicated by @jose.galarza you are typing in the interpreter in IDLE.

I'd recommend only using this for testing expressions, and create a new file, save and run it. At least then you will avoid what looks like incorrect indentation. enter image description here

Or download and install Spyder or another IDE.

Spyder

srattigan
  • 665
  • 5
  • 17