Lesson 10: Binary search

posted Dec 17, 2019, 8:16 AM by Attila Lengyel
upper = int(input("Give me the max:"))
lower = int(input("Give me the min:"))

guess = int(input("Guess a number in between:"))

while guess > upper or guess < lower:
print("Wrong number! Try again.")
guess = int(input("Guess a number in between:"))


import math

print(math.ceil(34.7))
print(math.floor(34.7))

xyx = math.floor((upper + lower)/2)
while xyx != guess:
print("Is it", xyx,"?")
answer= input("yes or no?:")
if answer == "no":
answer = input("Is it lower or higher?")
print(answer)
if answer == "lower":
upper = xyx
else:
lower = xyx
xyx = math.floor((upper + lower)/2)


Comments