Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write a python function for this question. Thank you. Write a function named game () that accepts one argument, the number of players. The
Please write a python function for this question. Thank you.
Write a function named game () that accepts one argument, the number of players. The game () function should complete the following tasks: Initialize a List of 9 empty Strings representing the 9 squares in the Tic-Tac-Toe board O HINT: This could be 9 Strings with each containing a single space character Draw the initial (empty) game grid Setup a for loop that repeats 9 times o If it's a human player's turn: . Prompt for a grid location to place their marker (ie: "A1") . If the selected location is outside the game grid (ie: "Al") . Continue to prompt the player until a a valid grid location is entered . If the selected grid location is not empty: . Continue to prompt the player until an empty grid location is entered . Update the corresponding List location with the correct player marker (x or O) o Else if it's the computer player's turn: . Select a random, empty grid location and place the o marker. o Draw the updated grid including the player's marker o call the check() function with the List as an argument to determine if there's a winner o If a player has won the game: . Display winning message and end the game () function Display "game is a tie" message as shown in the example outputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started