Python:期望在循环外面的缩进块

时间:2016-02-01 02:13:39

标签: python list for-loop indentation

有人可以解释为什么我一直收到错误消息:'期望缩进块'在这个python代码?代码之前正在运行,但是当我尝试运行代码时,我现在继续在IDLE上收到此消息。我将不胜感激任何帮助。我也包括了一条消息图片。

Error Message

`def coordinates():
"""
input none
output is a an array of the sequence of coordinates representing spaces inside and outside the bedroom
"""
sleepHistory = [0,0,0,0,0,0]
sleepHistory[0]=[0,0]
wakeUp = 0
escape = 0
start = [0,0]
one =[1,-1]



for i in range(1,6): 
    onestep = random.choice(one)
    facing = direction()
    if((facing == 'down') or (facing == 'up')):
        start =  [start[0] + onestep, start[1]]
        sleepHistory[i] = start

    if((facing == 'right') or facing == 'left'):
        start = [start[0], start[1] + onestep]
        sleepHistory[i] = start
if (sleepHistory[2] == [0,0] or sleepHistory[2] == sleepHistory[4]):
    return coordinates();
if ((sleepHistory[1] == sleepHistory[3]) or (sleepHistory[3] == sleepHistory[5])):
    return coordinates();
return sleepHistory`

1 个答案:

答案 0 :(得分:1)

假设您将标签设置为间隔为4。您的代码可能如下所示

    for i in range(1,6):                 # indented by one tab
        onestep = random.choice(one)    # indented by 8 spaces

但是Python将一个标签计为等于8的间距

所以块看起来缩进,但不是根据Python