print "Think of a number from 1 to 100." # start with the range 1-100 smallest = 1 largest = 100 # initialize answer to prevent NameError answer = "" while answer != "equal": # make a guess guess = (smallest + largest) / 2 answer = raw_input( "Is your number 'more', 'less'," \ " or 'equal' to " + str(guess) + "? " ) # update the range of possible numbers if answer == "more": smallest = guess + 1 elif answer == "less": largest = guess - 1 print "I got it!"