我正在使用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
答案 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:
>>> 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)
检查以确保您使用标签用于缩进或空格,并确保缩进是相同类型。