Lesson 14: Binary search... for guessing

posted Mar 22, 2019, 7:18 AM by Attila Lengyel
print("Think of a number between 0 and 100!")

answer = ""

upper = 100
lower = 0

import math as m

while answer != "correct":
guess = m.floor((upper - lower)/2 + lower)
print("Did you guess", guess, "?")
answer = input()
if answer == "correct":
print("You thought of", guess,".")
elif answer == "low":
lower = guess
elif answer == "high":
upper = guess


Comments