We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
def print_board(board): for row in board: print(" | ".join(row)) print("-" * 5)
def check_winner(board): # Check rows for row in board: if row[0] == row[1] == row[2] != ' ': return True
# Check columns for col in range(3): if board[0][col] == board[1][col] == board[2][col] != ' ': return True # Check diagonals if board[0][0] == board[1][1] == board[2][2] != ' ': return True if board[0][2] == board[1][1] == board[2][0] != ' ': return True return False
def is_board_full(board): for row in board: for cell in row: if cell == ' ': return False return True
def tic_tac_toe(): board = [[' ' for _ in range(3)] for _ in range(3)] player = 'X'
print("Let's play Tic Tac Toe!") while True: print_board(board) row = int(input("Enter row (0, 1, or 2): ")) col = int(input("Enter column (0, 1, or 2): ")) if board[row][col] != ' ': print("Cell already taken. Try again.") continue board[row][col] = player if check_winner(board): print_board(board) print(f"Player {player} wins!") break elif is_board_full(board): print_board(board) print("It's a tie!") break player = 'O' if player == 'X' else 'X'
tic_tac_toe()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
def print_board(board):
for row in board:
print(" | ".join(row))
print("-" * 5)
def check_winner(board):
# Check rows
for row in board:
if row[0] == row[1] == row[2] != ' ':
return True
def is_board_full(board):
for row in board:
for cell in row:
if cell == ' ':
return False
return True
def tic_tac_toe():
board = [[' ' for _ in range(3)] for _ in range(3)]
player = 'X'
tic_tac_toe()
The text was updated successfully, but these errors were encountered: