Create a program that guesses a secret number using bisection search!
The user thinks of an integer between 0 (inclusive) and 100 (not inclusive). The computer, using bisection search, gives a hint and the user responds with h (high), l (low) or c (right)
The computer will hunch until it hits.
My code:
print("Please think of a number between 0 and 100!")
print("#Enter 'h' to indicate the guess is too high.\
Enter 'l' to indicate the guess is too low.\
Enter 'c' to indicate I guessed correctly.")
#Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low.
#Enter 'c' to indicate I guessed correctly.
inicio =0
fim =100
meio = round((inicio +fim)/2)
guess = input("Is your secret number {}?:".format(meio))
while guess != "c":
if guess == "h":
fim =meio
meio = round((inicio + fim)/2)
guess = input("Is your secret number {}?:".format(meio))
elif guess == "l":
inio =meio
meio = round((inio +fim)/2)
guess = input("Is your secret number {}?:".format(meio))
else:
print("Sorry, I did not understand your input.")
guess = input("Is your secret number {}?:".format(meio))
print("Game over. Your secret number was:{}".format(meio))
What's wrong with the code?