public
Created

Number guesser

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/env python
 
lower, upper = 1, 100
 
print "Guess a number between %s and %s (inclusive)." % (lower, upper)
 
while lower < upper:
mid = (lower + upper) / 2
guess = raw_input("Is your number higher than %s? (y/n): " % (mid))
if guess == 'y':
lower = mid + 1
else:
upper = mid
 
print "Your number is %s!" % (lower)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.