tictactoe.py
def winner(board):
    """
    Returns the winner of the game, if there is one.
    """

    # No winner at start
    winner = None

    for idx, _ in enumerate(board):
        # Single diagonal check
        if idx == 0:
            if (
                board[idx][idx] == board[idx + 1][idx + 1]
                and board[idx + 1][idx + 1] == board[idx + 2][idx + 2]
            ):
                winner = board[idx][idx]

        # Reverse diagonal check
        elif idx == 2:
            if (
                board[0][idx] == board[1][idx - 1]
                and board[1][idx - 1] == board[idx][idx - 2]
            ):
                winner = board[0][idx]

        # Horizontal Check
        if board[idx][0] == board[idx][1] and board[idx][1] == board[idx][2]:
            winner = board[idx][0]

        # Vertical Check
        elif board[0][idx] == board[1][idx] and board[1][idx] == board[2][idx]:
            winner = board[0][idx]

        # Check if there is winner
        if winner:
            return X if winner == "X" else O

    return None

    Returns the winner of the game, if there is one.
    
Returns the winner of the game, if there is one.
Returns the winner of the game if there is one .
def winner(board):
    winner = None
    for idx, _ in enumerate(board):
        if idx == 0:
            if (
                board[idx][idx] == board[idx + 1][idx + 1]
                and board[idx + 1][idx + 1] == board[idx + 2][idx + 2]
            ):
                winner = board[idx][idx]
        elif idx == 2:
            if (
                board[0][idx] == board[1][idx - 1]
                and board[1][idx - 1] == board[idx][idx - 2]
            ):
                winner = board[0][idx]
        if board[idx][0] == board[idx][1] and board[idx][1] == board[idx][2]:
            winner = board[idx][0]
        elif board[0][idx] == board[1][idx] and board[1][idx] == board[2][idx]:
            winner = board[0][idx]
        if winner:
            return X if winner == "X" else O
    return None
def winner ( board ) : winner = None for idx , _ in enumerate ( board ) : if idx == 0 : if ( board [ idx ] [ idx ] == board [ idx + 1 ] [ idx + 1 ] and board [ idx + 1 ] [ idx + 1 ] == board [ idx + 2 ] [ idx + 2 ] ) : winner = board [ idx ] [ idx ] elif idx == 2 : if ( board [ 0 ] [ idx ] == board [ 1 ] [ idx - 1 ] and board [ 1 ] [ idx - 1 ] == board [ idx ] [ idx - 2 ] ) : winner = board [ 0 ] [ idx ] if board [ idx ] [ 0 ] == board [ idx ] [ 1 ] and board [ idx ] [ 1 ] == board [ idx ] [ 2 ] : winner = board [ idx ] [ 0 ] elif board [ 0 ] [ idx ] == board [ 1 ] [ idx ] and board [ 1 ] [ idx ] == board [ 2 ] [ idx ] : winner = board [ 0 ] [ idx ] if winner : return X if winner == "X" else O return None
Returns the winner of the game, if there is one.
Returns the winner of the game if there is one .
"""
    Returns the winner of the game, if there is one.
    """ # No winner at start # Single diagonal check # Reverse diagonal check # Horizontal Check # Vertical Check # Check if there is winner
board