1
,所以我做涉及二维数组一个游戏,我要求用户输入一个网格的高度和宽度,这里是使电网Python的索引错误
Grid=[['O'for x in range(gridS[0])]for y in range(gridS[1])]
我的代码后来改变电网[0]和1的gridx和Y
然后我尝试的玩家加入到网格,我再次询问用户有多少玩家(存储在变量的对手)在玩,然后加入很多玩家
if opponents>0:
Grid[gridX-1][gridY-2]='P'
if opponents>1:
Grid[0][(gridY-2)]='P'
if opponents>3:
Grid[gridX-1][0]='P'
ho当测试时,它出现了这个错误:
>>> How many bots do you want to play against?
>>> 10
>>> Please enter a number between 0 and 3
>>> 2
2
Grid[gridX-1][gridY-2]='P'
IndexError: list assignment index out of range
这是一个*列表*不是数组。 –
我的老师说数组 - 我的不好 –
这是一个迂腐点,松散地说,它可以被称为数组,但最好是精确的。 –