我似乎无法弄清楚我在哪里错误地格式化了这个python代码。我确保这些缩进是正确的,但我不知道为什么会出现这种错误。我在这里缺少什么?
width = passageWidth(checkChamber, chamberMaxLength)
if (width >= 10):
point = width/2
else:
width = 2
r = random.randint(1, 19) #think aboout adding stairs later!!!
if (r <= 14):
if (r == 5):
door(False, 0) #continue 20, end door
elif (r == 10):
x = random.randint(1, 10)
if (x == 1):
door(False, -1) #continue 20, secret door
else:
#continue 20, dead end
elif (r <= 9): ########### Error occurs here ##############
if (r <= 6):
if (r <= 2):
#continue 30
elif (r == 3):
door(False, 0) #continue 30, door right at 20
elif (r == 4):
door(False, 0) #continue 30, door left at 20
else:
elif (r >= 6):
if (r >= 8):
passage(False, 0) #continue 30, passage left at 20
else:
passage(False, 0) #continue 30, passage right at 20
else:
elif (r <= 12):
#continue 20 plus point, turn left, continue 10 plus point
else:
#continue 20 plus point, turn right, continue 10 plus point
#offset edges along passage by point value to define sides of passage
elif (r <= 19):
#create Chamber
else:
#stairs
#Check if space is available, if not, terminate!
答案 0 :(得分:2)
else:
#continue 20, dead end
elif (r <= 9):########### Error occurs here ##############
Python不允许空块。如果你写
else:
pass # continue 20, dead end
elif (r <= 9):
错误应该消失。 (要消除所有这些错误,您需要在多个地方执行此操作。)
顺便说一下,Python首选样式是而不是来围绕控件表达式编写括号,除非你需要它们将条件分成多行。也就是说,你应该写
elif r <= 9:
此外,#
两侧应始终有空格,引入评论。真正的Python解析器并不关心,但人类会这么做,并且“快速而肮脏”#34;解析器也可能关心(例如,这就是为什么你的问题中的代码没有正确突出语法)。