0
Create a program that gives a secret number using bisection search !
The user thinks of an integer between 0 (inclusive) and 100 (not included). The computer, using bisection search, gives a guess and the user responds with h (high), l (low) or c (right)
The computer will guess until it’s right.
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?
In fact, I went to pass this program on an edx automatic tester and received the error: https://ibb.co/nkGpBn
– Ed S
can understand what’s going on?
– Ed S