Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Think of a number between 0 and 100. How could be make a computer guess the number? The simplest method is to just guess every

Think of a number between 0 and 100. How could be make a computer guess the number?

The simplest method is to just guess every value. This is a poor method. In real life, you would never use this solution.

If someone had a number you were trying to guess, you would gain information with every failed guess.

In our guessing game, when the guess is incorrect the person with the secret number will say "higher" or "lower". This gives the other player information about where to guess next. (You can also play with "hotter" or "colder" but that algorithm is a bit harder.)

Here is a basic layout of the higher/lower algorithm. Implement it in Python.

Set three values low=0, high=101, guess=50

While you have not guess correctly

Ask the user if it is correct, higher, or lower

If the secret number is lower than the guess set high=guess and your next guess is (guess-low)//2+low

If the secret number is higher than the guess set low=guess and your next guess is (high-guess)//2+guess

If the input was not valid, say "I did not understand." and make the same guess again.

image text in transcribed

Hello. Pick a secret number between 0 and 100 Is your secret number 50 Enter yes/higher/lower: lower Next is 25 Is your secret number 25 Enter yes/higher/lower: higher Next is 37 Is your secret number 37 Enter yes/higher/lower lower Next is 31 Is your secret number 31 Enter yes/higher/lower: lower Next is 28 Is your secret number 28 Enter yes/higher/lower: lower Next is 26 Is your secret number 26 Enter yes/higher/lower: higher Next is 27 Is your secret number 27 Enter yes/higher/lower: yes Great

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago