Question: Binary Search, or Make the Computer Play Hi-Lo write a Python program that will interactively guess a number from 1 to any number using a

Binary Search, or Make the Computer Play Hi-Lo write a Python program that will interactively guess a number from 1 to any number using a binary search (for 1-100, guess 50, if too low, 75, etc.). For this program, the computer will play the Hi-Lo guessing game: you think of a number from 1-100 (or 1-1000) and the computer should guess it in 7 or fewer tries. Hint:

guess = (hi + lo) // 2 

Example: The computer asks for a range. You say 1 to 100. You pick a number (99 shown here), then the computer guesses, and you say whether their guess was too high (>) or too low (<) until the computer guesses correctly.

What is the maximum range, 1 to ___? 100 Is it 50 ? Tell me too high with >, too low with <, or y if I got it! < Is it 75 ? Tell me too high with >, too low with <, or y if I got it! < Is it 88 ? Tell me too high with >, too low with <, or y if I got it! < Is it 94 ? Tell me too high with >, too low with <, or y if I got it! < Is it 97 ? Tell me too high with >, too low with <, or y if I got it! < Is it 99 ? Tell me too high with >, too low with <, or y if I got it! y Wow! I got it! 99 Thanks for the game! >>> 
 program your app to tell when there's no solution (like if I say 3 is too low, but 4 is too high): What is the maximum range, 1 to ___? 5 Is it 3 ? Tell me too high with >, too low with <, or y if I got it! < Is it 4 ? Tell me too high with >, too low with <, or y if I got it! > I think you're messing with me. Thanks for the game! 

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!