Skip to content

Instantly share code, notes, and snippets.

@stevekrenzel
Created February 12, 2012 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevekrenzel/1806675 to your computer and use it in GitHub Desktop.
Save stevekrenzel/1806675 to your computer and use it in GitHub Desktop.
Number guesser
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment