# Number Guessing Game: Human Guesses from random import randint from math import log min,max = 1,1024 lower,upper = min-1,max+1 # lower and upper bound for WRONG answers n = randint(min,max) # number to be guessed print "Guess a number between",min,"and",max counter = 0 # counts number of guesses guess = -1 # start loop with wrong guess while guess!=n: guess = input("What's your guess: ") counter += 1 # same as counter = counter + 1 if guess <= lower or guess >= upper: print "HA HA HA! I already told you that the number is greater than",lower,"and less than",upper,". Humans are stupid!" else: if guessn: print "Too large!" upper = guess # else # while print "You guessed it in",counter,"tries" limit = int(log(max-min+1)/log(2.0)+0.5) # number of guesses required if counter>limit: print "But you need at most",limit," so you LOSE!" # Note the log function of Python computes the natural log. Log base a of b # is equivalent to log(b)/log(a).