python在一个脚本中的多个函数

时间:2018-06-11 16:14:26

标签: python syntax-error

这个井字游戏脚本有问题。由于某种原因,我的赢家'功能导致错误。但是我调整了胜利者函数,我在print语句后的行上出现语法错误。当我评论胜利者函数时,脚本按预期运行。我无法看到语法错误的位置。感谢。

def winner(board):
    if board[0][0]==board[0][1]==board[0][2] or board[1][0]==board[1][1]==board[1][2] or board[2][0]==board[2][1]==board[2][2] or board[0][0]==board[1][0]==board[2][0] or board[0][1]==board[1][1]==board[2][1] or board[0][2]==board[1][2]==board[2][2] or board[0][0]==board[1][1]==board[2][[2] or board[0][2]==board[1][1]==board[2][0]:
        print('Player {} wins!!!'.format(player))
        return False
    else:
        return True

def move(coord, player):
    marker = ' X '
    if player == 2:
        marker = ' O '
    if coord == '0,0':
        board[0][0] = marker
    elif coord == '0,1':
        board[0][1] = marker
    elif coord == '0,2':
        board[0][2] = marker
    elif coord == '1,0':
        board[1][0] = marker
    elif coord == '1,1':
        board[1][1] = marker
    elif coord == '1,2':
        board[1][2] = marker
    elif coord == '2,0':
        board[2][0] = marker
    elif coord == '2,1':
        board[2][1] = marker
    elif coord == '2,2':
        board[2][2] = marker

board = [[(0,0), (0,1), (0,2)],
        [(1,0), (1,1), (1,2)],
        [(2,0), (2,1), (2,2)]]

turn = 2
while True:
    print('\n'.join(map(str, board)))
    player = turn % 2 + 1
    x = input('Player {}, where will you play? (i.e. 0,0 for upper left) '.format(player))
    move(x,player)
    winner(board)
    turn += 1

1 个答案:

答案 0 :(得分:1)

这只是一个简单的错误,你的代码是有效的:你在这部分条件中有一个额外的def factor(self): return self.typ.factor if self.typ else None

[

删除额外的括号,它将按预期工作!

  • 我注意到了,因为我将代码复制到了记事本++,当它站在其中一个支架上时它会突出显示匹配的支架。
    我用箭头键浏览了这个条件并注意到它变成了红色:

    enter image description here