Create a gist now

Instantly share code, notes, and snippets.

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
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