你能帮我解决python while循环错误吗?

时间:2018-01-31 15:55:32

标签: python indentation

这是代码

GrassFilledX = GrassGenX
GrassFilledY = GrassGenY

GrassFillL = True

while GrassFillL == True:
    if gx == hgx or hgx2:



while not crashed:

错误说

while not crashed:
^
IndentationError: expected an indented block

1 个答案:

答案 0 :(得分:1)

Python期望在if语句之后出现缩进块。

如果您想要空块,请使用pass

while GrassFillL == True:
    if gx == hgx or hgx2:
        pass

while not crashed:

这在其他语言中与一对空括号(例如if(condition){})具有相同的效果。在Python中,不允许将块保留为空,您必须至少在块中有一个NOP语句pass,以使程序有效。

Thispass的类似(但基本相同)的用例。