Question: IN PYTHON The function should start by choosing a random number in the range from 1 up to and including n. The function should then

IN PYTHON

The function should start by choosing a random number in the range from 1 up to and including n.

The function should then repeatedly ask the user to enter to guess the chosen number. When the user guesses correctly, the function should print a You got it message and terminate. Each time the user guesses incorrectly, the function should indicate whether the guess was too high or too low.

If the user types something other than an integer, the function should recover gracefully

>>> guess(100)

Enter your guess: fifty

That was not a valid number.

Enter your guess: 50

Too high

Enter your guess: 25

Too low

Enter your guess: 38

Too high

Enter your guess: 31

Too high

Enter your guess: 28.5

That was not a valid number.

Enter your guess: 28

Too high

Enter your guess: 26

You got it!

>>>

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!