# hilo.py # The computer asks the user for two numbers in a range # The computer then asks the user to think of a number within that range # The computer then provides a series of guesses and asks the user if # guess is correct # If the guess is too high, the user types "h" # If the guess is too low, the user types "l" # If the guess is correct, the user types "y" # If the guess was correct, # the program then prints "Yay!" and quits lo = int(raw_input("Please enter the lowest number in range: ")) hi = int(raw_input("Please enter the highest number in range: ")) print "Please think of a number in your range." while True: guess = (hi + lo) / 2 user_answer = raw_input("Is your number %d? " % guess) if user_answer == 'h': hi = guess elif user_answer == 'l': lo = guess elif user_answer == 'y': print "Yay!" quit()