Hi,
I am completely new to programming and am strugling with my assignment Tic Tac Toe in Python code. Can somebody please help me by pointing out my mistakes? I am sure there are lots of mistakes, but I am blind to them and how to solve them.
I am completely new to programming and am strugling with my assignment Tic Tac Toe in Python code. Can somebody please help me by pointing out my mistakes? I am sure there are lots of mistakes, but I am blind to them and how to solve them.
def print_board(board): for row in board: print(row) def check_winner(board, current_player): if board[0][0] == board[0][1] == board[0][2] != "": return True elif board[1][0] == board[1][1] == board[1][2] != "": return True elif board[2][0] == board[2][1] == board[2][2] != "": return True elif board[0][0] == board[1][0] == board[2][0] != "": return True elif board[0][1] == board[1][1] == board[2][1] != "": return True elif board[0][2] == board[1][2] == board[2][2] != "": return True elif board[0][0] == board[1][1] == board[2][2] != "": return True elif board[2][0] == board[1][1] == board[0][2] != "": return True else: return False def update_board(board, row, col, current_player): board[row][col] = current_player def verify_entry(board, row, col): if board[row][col] == " ": return True else: return False if row in range(0,3) and col in range(0,3): return True else: return False board = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]] print_board(board) # prints an empty board current = None moves = 0 while moves < 9 and not check_winner(board, current): # game over? # play current = "X" if (current == None or current == "O") else "O" row, col = map(int, input("Enter the move for " + current + ": ").split(",")) while not verify_entry(board, row, col): print("Wrong entry. Think again!") row, col = map(int, input("Enter the move for " + current + ": ").split(",")) update_board(board, row, col, current) print_board(board) # prints the current board moves = moves + 1 if moves < 9: print(current + " WON!")