Question: A Guessing Game (python) Youll need to import the randrange() function from the random module. Your program must do the following: Obtain a value for

A Guessing Game (python)

Youll need to import the randrange() function from the random module. Your program must do the following:

Obtain a value for the target number from the randrange() function. This number should be between 1 and 100.

Prompt for the total number of players (num players). Print the message, Im thinking of a number between 1 and 100. Guess what it is.

Initialize the player number player to 0.

Enter a for-loop that iterates up to 100 times.

The first statement in the body of the for-loop should prompt the appropriate player for their guess. It might be less confusing to create the prompt outside the input() function. For example, prompt = Player + str(player + 1) + ?

Once a guess has been obtained, its compared with the target number. If its too high, the message Too high. is printed. If its too low, the message Too low. is printed. If the guess if correct, the program announces the winning player and a break statement is used to exit the loop which ends execution of the program.

If a guess isnt correct, the player number is set to the next player (as specified above).

Include docstrings.

Enter number of players: 3

Im thinking of a number between 1 and 100. Guess what it is.

Player 1? 50

Too low.

Player 2? 75

Too high.

Player 3? 62

Too low.

Player 1? 68

Too low.

Player 2? 71

Too low.

Player 3? 73

***PLAYER 3 WINS!***

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!