Sep-28-2020, 10:39 AM
I'm a freshman, and have this assignment to just fill inn the missing codes/def functions.
I think I'm done but get the wrong output.
When I run it, the program ask for an input, example 0,1. This input will split and represent a place in the board.
But I got the output "Wrong entry. Think again!". The place is not taken yet.
Can someone help me, or tell me what's missing/wrong with my functions?
I use Python 3.8.5
I think I'm done but get the wrong output.
When I run it, the program ask for an input, example 0,1. This input will split and represent a place in the board.
But I got the output "Wrong entry. Think again!". The place is not taken yet.
Can someone help me, or tell me what's missing/wrong with my functions?
I use Python 3.8.5
def print_board(board): print(board[0][0] + '|' + board[0][1] + '|' + board[0][2]) print("-+-+-") print(board[1][0] + '|' + board[1][2] + '|' + board[1][2]) print("-+-+-") print(board[2][0] + '|' + board[2][1] + '|' + board[2][2]) def check_winner(board, current): if board[0][0] == board[0][1] == board[0][2] == current: return True elif board[1][0] == board[1][1] == board[1][2] == current: return True elif board[2][0] == board[2][1] == board[2][2] == current: return True elif board[0][0] == board[1][0] == board[2][0] == current: return True elif board[0][1] == board[1][1] == board[2][1] == current: return True elif board[0][2] == board[1][2] == board[2][2] == current: return True elif board[0][0] == board[1][1] == board[2][2] == current: return True elif board[2][0] == board[1][1] == board[0][2] == current: 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