ADD MORE Comments in the code board = [“1”, “2”, “3”, “4”, “5”,…
Question Answered step-by-step ADD MORE Comments in the code board = [“1”, “2”, “3”, “4”, “5”,… ADD MORE Comments in the codeboard = [“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”]def print_board(): print(board[0] + “|” + board[1] + “|” + board[2]) print(“-+-+-“) print(board[3] + “|” + board[4] + “|” + board[5]) print(“-+-+-“) print(board[6] + “|” + board[7] + “|” + board[8])def check_win(): # check rows if (board[0] == board[1] and board[1] == board[2]): return board[0] if (board[3] == board[4] and board[4] == board[5]): return board[3] if (board[6] == board[7] and board[7] == board[8]): return board[6] # check columns if (board[0] == board[3] and board[3] == board[6]): return board[0] if (board[1] == board[4] and board[4] == board[7]): return board[1] if (board[2] == board[5] and board[5] == board[8]): return board[2] # check diagonals if (board[0] == board[4] and board[4] == board[8]): return board[0] if (board[2] == board[4] and board[4] == board[6]): return board[2] return Nonedef check_full(): for i in range(9): if (board[i] != “X” and board[i] != “O”): return False return Truedef make_move(player, move): if (move < 1 or move > 9): print(“Invalid move!”) return False if (board[move-1] == “X” or board[move-1] == “O”): print(“That square is already taken!”) return False board[move-1] = player return Truedef get_move(player): move = int(input(player + “, enter your move (1-9): “)) return movedef main(): print(“Welcome to Tic Tac Toe!”) player1 = input(“Player 1, enter your name: “) player2 = input(“Player 2, enter your name: “) while (True): move = get_move(player1) make_move(player1, move) print_board() winner = check_win() if (winner != None): print(winner + ” wins!”) break full = check_full() if (full): print(“It’s a tie!”) break move = get_move(player2) make_move(player2, move) print_board() winner = check_win() if (winner != None): print(winner + ” wins!”) break full = check_full() if (full): print(“It’s a tie!”) breakmain() Computer Science Engineering & Technology Python Programming MKS 11X Share QuestionEmailCopy link Comments (0)


