Python - 我收到缩进错误,但我没有看到.标签和空格不混合

Cal*_*ney 4 python indentation

我的代码是:

90              if needinexam > 100:
91                  print "We are sorry, but you are unable to get an A* in this class."
92              else:
93                  print "You need " + final + "% in your Unit 3 controlled assessment to get an A*"
94          
95          elif unit2Done == "n":
96              
97          else:
98              print "Sorry. That's not a valid answer."
Run Code Online (Sandbox Code Playgroud)

而错误是:

line 97
    else:
       ^
IndentationError: expected an indented block
Run Code Online (Sandbox Code Playgroud)

我完全不知道为什么我会收到这个错误,但也许你们可以帮助我.围绕它有很多if/else/elif语句,这可能让我感到困惑.非常感谢任何帮助,谢谢!

编辑:将"传递"或代码添加到elif语句只是将相同的错误移动到第95行.

Ósc*_*pez 14

试试这个:

elif unit2Done == "n":
    pass # this is used as a placeholder, so the condition's body isn't empty
else:
    print "Sorry. That's not a valid answer."
Run Code Online (Sandbox Code Playgroud)

这里的问题是unit2Done == "n"条件的身体不能为空.在这种情况下,pass必须使用a作为一种占位符.

  • @CalCourtney然后很可能确实这是一个缩进问题.使用好的文本编辑器,复制整个文本,并确保将所有前导空格替换为空格或制表符,而不将它们混合 (2认同)
  • @CalCourtney然后有可能某些条件没有在正确的级别对齐,我只能推测这个,因为问题中的代码只是一个片段. (2认同)