elif python 3.5中的缩进错误

时间:2016-11-26 19:52:04

标签: python

我正在使用Python 3.5空闲。 我在使用elif函数时出现缩进错误。 这是我输入的代码:

>>> num = 7

>>> if num == 5:

    print("number is 5")

... elif num == 11:

  File "<stdin>", line 2

    elif num == 11:
       ^
IndentationError: expected an indented block

2 个答案:

答案 0 :(得分:0)

您需要在elif之后编写一些代码。例如:

>>> num = 7
>>> if num == 5:
...     print("Number is 5")
... elif num == 11:
...     print("Number is 11")
...
>>> if num == 5:
...     print("Number is 5")
... elif num == 11:
...     print("Number is 11")
... elif num == 7:
...     print("Number is 7")
...
Number is 7
>>>

elif num == 11:

之后按Enter键会发生这种情况
>>> if num == 5:
...     print("Number is 5")
... elif num == 11:
...
  File "<stdin>", line 4

    ^
IndentationError: expected an indented block
>>>

如果您因某些原因不想做任何事情,请使用pass

>>> num = 11
>>> if num == 5:
...     print("Number is 5")
... elif num == 11:
...     pass
... elif num == 7:
...     print("Number is 7")
...
>>>

答案 1 :(得分:-1)

检查以确保您使用标签用于缩进或空格,并确保缩进是相同类型。