This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable,
visit the help center。
7年前关闭。
我的代码收到“无效语法”错误,但我不知道为什么。
我的代码应创建一个二维零列表,然后将零之一更改为一,并检查某些列表值,以查看它是否将返回1或仅返回零。
我定义了一个函数,该函数应返回相邻单元格值的列表,但是由于某种原因,会出现语法错误。这是我的代码:
def test(x,y):
spotX = [(x-1)%height,0,(x+1)%height]
spotY = [(y-1)%height,0,(y+1)%height]
val = []
for a in range(3):
for b in range(3):
if a and b != 2:
val.append(newBoard[spotX[a]][spotY[b]]
return val
语法错误是“return val”行。