''' Purpose: play guess a number ''' # brainstorming - questions to ask # greater than or less than halfway point # this one is really great, because it will always throw away half of the numbers # even or odd/divisible by 2 # this gets rid of half the numbers, which is very handy! # but afterwards there is not a repeatable way to get rid of half of the numbers # is it an integer # specify max number n = 100000 # note: the file had n set to 10000 instead of 100000 low = 0 high = n # start the game print( 'Think of a number from 0 to', n ) still_looking_for_number = True # initialize our loop variable while (still_looking_for_number == True ) : print() print( "Low:", low ) print( "High:", high ) midpoint = ( high + low ) // 2 prompt = "Is your number less than " + str( midpoint ) + " [yes/no]?: " reply = input( prompt ) reply = reply.strip() reply = reply.lower() if ( reply == "yes" ) : high = midpoint - 1 # if less than midpoint, update high guess to one less than midpoint else : prompt = "Is your number " + str( midpoint ) + " [yes/no]?: " reply = input( prompt ) reply = reply.strip() reply = reply.lower() if ( reply == "yes" ) : print( "I got it!" ) still_looking_for_number = False else : low = midpoint + 1 # if not less than or equal to midpoint, must be greater than midpoint -> update low to midpoint + 1 # ??? # we throw away half(ish) of the numbers each time through the loop # the while() loop will keep repeating until the test expression evaluates to False