board = [[" "]*3 for _ in range(3)] players = ["X", "O"] current_player = 0 cell=0 line=1 while True: print("\n".join([" | ".join(row) for row in board])) row, col = map(int, input(f"Player {players[current_player]} (row col): ").split()) if board[row][col] == " ": board[row][col] = players[current_player] if any(all(cell == players[current_player] for cell in line) for line in [board[row], [board[i][col] for i in range(3)], [board[i][i] for i in range(3)], [board[i][2-i] for i in range(3)]]): print(f"Player {players[current_player]} wins!"); break if all(cell != " " for row in board for cell in row): print("It's a draw!"); break current_player = 1 - current_player else: print("Cell occupied! Try again.") ''' | | | | | | Player X (row col): 1 1 | | | X | | | Player O (row col): 0 0 O | | | X | | | Player X (row col): 2 2 O | | | X | | | X Player O (row col): 0 1 O | O | | X | | | X Player X (row col): 2 0 O | O | | X | X | | X Player O (row col): 0 2 O | O | O | X | X | | X Player O wins! '''