In this problem, you'll create a program that guesses a secret number! Note: your program should use input to obtain the user's input! Be sure to handle the case when the user's input is not one of h, l, or c.
When the user enters something invalid, you should print out a message to the user explaining you did not understand their input. Then, you should re-ask the question, and prompt again for input. For example:
Is your secret number 47? 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. y Sorry, I did not understand your input. Is your secret number 47?
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. c
below are code....
max_num=100
min_num=0
guess = int(abs(max_num/2))
print("Please think of a number between 0 and 100!")
for i in range(min_num,max_num):
text = "Is your secret number "+str(guess)+"?\nEnter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. "
xx = raw_input(text)
if(xx == 'h'):
max_num = guess
guess = int((guess + min_num)/2)
elif(xx == 'l'):
min_num = guess
guess = int((guess + max_num)/2)
elif(xx == 'c'):
print("Game over. Your secret number was:"+str(guess))
else:
print("Sorry, I did not understand your input.")
xx = str(input(text))