Question: Number Guess Python Program *************************************************************** Modify that program so that the user is asked to think of a secret number and the computer guesses that
Number Guess Python Program
***************************************************************
Modify that program so that the user is asked to think of a secret number and the computer guesses that number. Here is the interaction:
The computer asks the user for the range.
The user inputs the range and thinks of a secret number in the range.
The computer tries to guess the secret number in as little attempts as possible.
For each guess, the user should enter:
> if the secret number is greater than the guess;
< if the secret number is less than the guess; and
= if the secret number is equal to the guess.
With the above information, the computer adjusts the range and guesses again.
Here is a sample run (user input was changed to red for improved readability):
Enter the smaller number in the range: 0 Enter the larger number in the range: 100 Now think of a number between 0 and 100 . Hit enter to continue... I'm trying to guess your number. I know it is between 0 and 100 Is your number 50 ? Enter =, <, or >: < I'm trying to guess your number. I know it is between 0 and 49 Is your number 24 ? Enter =, <, or >: > I'm trying to guess your number. I know it is between 25 and 49 Is your number 37 ? Enter =, <, or >: < I'm trying to guess your number. I know it is between 25 and 36 Is your number 30 ? Enter =, <, or >: = Hooray, I've got it in 4 tries!
* Notice how the computer always guesses in the middle of the range. * Use only integers. Use the // operator to get an integer quotient. For example: 5 / 2 = 2.5 and 5 // 2 = 2.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
