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
Get step-by-step solutions from verified subject matter experts
