''' Purpose: play guess a number ''' # specify max number n = 10000 # start the game print( 'Think of a number from 0 to', n ) low = 0 high = n looking_for_the_number = True # Variable that runs the loop while ( looking_for_the_number == True ): middle = ( low + high ) // 2 query = "Is the number less than " + str( middle ) + "?(yes/no) " reply = input( query ) if ( reply == 'yes' ) : # If the number is less than the middle, high = middle - 1 # Range of possible numbers is now low to mid - 1 else: # It's either equal to the middle or greater than the middle query = 'Is the number equal to ' + str( middle ) + "?(yes/no) " reply = input( query ) if ( reply == 'yes' ): looking_for_the_number = False # We found the number, exit the loop else: # It's not equal so it's greater than the middle low = middle + 1 # Range of possible numbers is from mid + 1 - high