Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

=+you think is being taxed when more money is printed? Why?

Answered: 1 week ago