Python-将对象循环到新位置时列出索引超出范围

Python-将对象循环到新位置时列出索引超出范围,python,indexing,Python,Indexing,我已经搜索了好几次了,我都不知道怎么回事。相关代码行为: WallList=[] def createWallList(): i=0 while i<=numberWalls: newWall=box(pos=(0,(arenaSize-(i*2))-1,0), height=.1, width=1, length=(randomValue(0,20)), color=color.green) WallList.append(newWall)

我已经搜索了好几次了,我都不知道怎么回事。相关代码行为:

WallList=[]
def createWallList():
    i=0
    while i<=numberWalls:
        newWall=box(pos=(0,(arenaSize-(i*2))-1,0), height=.1, width=1, length=(randomValue(0,20)), color=color.green)
        WallList.append(newWall)
        i=i+1

if WallList[i].pos.y>arenaSize:
    WallList[i].pos.y=-arenaSize

很抱歉这里有这么多,但我不知道出了什么问题。如果你们中有人能提供见解,那将非常有帮助。如有必要,我可以提供其他详细信息。

由于缩进错误,您会收到一个错误。下面是正在发生的事情:

i = 0
Is i <= numberWalls? Yes.
Make a new wall.
Increment i to 1.
Is i <= numberWalls? Yes.
Make a new wall.
Increment i to 2.
...
Increment i to numberWalls + 1.
Is i <= numberWalls? No.
if WallList[i] <- ERROR: there is no wallList[i]
i=0

我能帮你修一下缩进吗。
i = 0
Is i <= numberWalls? Yes.
Make a new wall.
Increment i to 1.
Is i <= numberWalls? Yes.
Make a new wall.
Increment i to 2.
...
Increment i to numberWalls + 1.
Is i <= numberWalls? No.
if WallList[i] <- ERROR: there is no wallList[i]