我正在研究GeekforGeeks网站上的教程,并注意到他们正在使用来检查数组中的点board[x,y],这是我从未见过的。我认为这行不通,但是当我运行程序时,一切都会按预期进行。
我尝试使用上面概述的方法和我更熟悉的方法(board[x][y])运行一个较小的代码示例,但是当我运行代码时,我得到了TypeError: list indices must be integers or slices, not tuple
我的代码:
board = [[1,1,1], [1,2,2], [1,2,2]]
win = 'True'
if board[1][1] == 2:
win = 'True by normal standards'
print(win)
if board[1, 1] == 2:
win = 'True by weird standards'
print(win)
print(win)
Run Code Online (Sandbox Code Playgroud)
他们的代码:
def row_win(board, player):
for x in range(len(board)):
win = True
for y in range(len(board)):
if board[x, y] != player:
win = False
continue
if win == …Run Code Online (Sandbox Code Playgroud)