"不能分配给运营商"错误

时间:2017-10-25 03:03:52

标签: python-3.x tic-tac-toe

我现在已经学习了大约一个月的编码,而且我正在使用列表制作一个初学者的tic tac toe游戏。我不知道为什么它会给我这个错误。给我语法错误的部分是" game_board [int(move) - 1] // 3 [int(move) - 1]%3 = player_piece"。有人可以给我一个初学者可以理解的简单修复吗?我需要在明天早上8点之前将其打开。

player_list = ['X', 'O']
player_num = 1
player_piece = player_list[player_num]
game_board = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
printTTT(game_board)
print()

while hasWinner(game_board) == False and movesLeft(game_board):
    player_num = (player_num + 1) % 2
    player_piece = player_list[player_num]
    move = input("Please enter a valid move Player " + player_piece + ". ")
    while moveValid(move, game_board) == False:
        move = input("Not a valid move. Please enter a valid move. ") 
    game_board[int(move) - 1] // 3 [int(move) - 1] % 3 = player_piece   
    printTTT(game_board)
    print()

if hasWinner(game_board) == True:
    print("Congratulations! Player " + player_piece + " wins!!!")
else:
    print("Tie game!")

1 个答案:

答案 0 :(得分:0)

您需要在列表索引中移动操作:

game_board[(int(move) - 1) // 3][(int(move) - 1) % 3] = player_piece

现在,你有一个数字后面的方括号。这是不允许的,这就是您遇到语法错误的原因。