Question
Does the python code below for a reverse guessing game in which the computer tries to guess the number in a person's mind use binary
Does the python code below for a reverse guessing game in which the computer tries to guess the number in a person's mind use binary search? If not, how can it be changed to use binary search?
import random
print(" Choose a number between 1 - 10 in mind!")
lowBound = 0 highBound = 10 response = '' randomNumber = random.randint(lowBound,highBound)
while response != "yes": print ("Is it ", randomNumber, " ?") response = input() if response == "higher": lowBound = randomNumber + 1 randomNumber = random.randint(lowBound,highBound) elif response == "lower": highBound = randomNumber - 1 randomNumber = random.randint(lowBound,highBound) elif response == "yes": print ("Game Over. I win.") break else: print ('"higher", "lower", or "yes" are valid responses.')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started