Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 4 (this question MAY BE GRADED) Write a Python program, in a file called number_guessing.py, to play a number guessing game with two
Question 4 (this question MAY BE GRADED) Write a Python program, in a file called number_guessing.py, to play a number guessing game with two players. The game is played for a fixed number of "sets" as pre-determined by the players. For each set, each player is given 2 tries to guess the value of a randomly generated number (between 1 and 6, inclusive). A different random number is used for each player, for each set. If the player guesses the number on the first try, they get 5 points (and don't have to guess again), if they guess the number on the second try, they get 3 points, otherwise they get no points. The player with the highest number of points, at the end of all sets, wins the game (or there can be a tie/draw). Your program should include the following functions: function main to do the following: . O obtain as input, the number of sets that the players wish to play O obtain the name of the two players for each set of the game, and for each player, randomly generate the number to be guessed compute and return the points for a player, at a given set, using the function computePoints (see description below) o print the results of each set (see sample output below) O print the winner of the game (after all sets are played) using the function printWinner (see description below) Note: Study the given sample input/output to see what and how the input should be obtained and how the output should be generated. O O function computePoints which, given the player name and the random number for a player, asks the player for their guesses, and computes and returns the number of points obtained (as described above) function printWinner which, given the total points and names of each player, prints the results (winner's name or "tie/draw" message).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Here is a Python program that implements the number guessing game with two players python import ran...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