Syntaxerror: unindent does not match any Outer indentation level

Asked

Viewed 8,846 times

2

What should I do when this error message appears: "Syntaxerror: unindent does not match any Outer indentation level"?

I cannot declare the Else of the variable. Follow a print of the problem and the code: inserir a descrição da imagem aqui

escada = 'Sim'
if escada == 'Sim':
    print('Subir na escada e trocar a lâmpada')
else:
    print('Suba na cadeira')
  • 3

    Copy and paste the text into your question instead of placing screenshots. In general, screenshots are bad enough to disrupt future searches, not be accessible to users with vision difficulties and make it harder for us to run the code on our machine to test, but in your case it’s even worse because you can’t tell just by looking, because the mistake may be in some blank space that we can not see.

  • 1

    I reiterate what @Pabloalmeida said, really the image is more disturbing than it helps. Your code seems to be indented, but keep in mind one thing, if you use 4 spaces (the recommended) in a chunk use throughout the code, the message seems to indicate that you used different levels of indentation in the code. Python requires the same level throughout the code, try to follow the convention of 4 spaces.

  • Thanks guys, I didn’t know it was bad. I’ll edit the question and put the code.

2 answers

-1

Indentation error, python for not having keys, is a sensitive language when declaring conditional, functions, among others. So the right way would be:

escada = "Sim"
if (escada):
    print("Subir na escada e trocar as lampadas")
else
    print("Vá pegar as escadas")
  • I tried to do it this way, but this error kept popping up.

  • @Alineat By msg vc is using different identation levels in the code, check this.

  • @Sidon, that’s what I don’t understand. I don’t know why he says I’m using different levels of identation, I left everything straight. if and Else are part of the first level and print is part of the second level, but it keeps giving error.

  • The problem may be in another part of the code, the error msg says that the part not identada not "house" with any other level of identaçao, do not look only in this excerpt of code. If it’s a single file, post it https://repl.it/, or other equivalent service, which we test. :-)

  • @Sidon, it seems like something with IDLE. If I use another code editor I can write without these errors.

  • 1

    Use the pycharm and you’ll never want anything else to work on python. :-)

  • The code of this answer has syntax error.

Show 2 more comments

-1

Actually we have a syntax error, this code works.

escada = "Sim"
if escada:
   print("Subir na escada e trocar as lampadas")
else:
   print("Va pegar as escadas")

>>> 'Subir na escada e trocar as lampadas'
  • The original code of the question is correct (and has no difference to your answer), tb works!

  • I know it’s correct, I just improved it, since the language allows me to write more cleanly. And if he actually stops to observe the code posted, he forgot the : right after Else, which is why I was making the mistake.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.