triclops200

guesser.py

Apr 29th, 2012
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. print "Choose a number between 1 and 100000"
  2. won = False
  3. guesses = 0
  4. l = 0
  5. h = 100000
  6. while not won:
  7.     guess = (h+l)/2
  8.     guesses += 1
  9.     print "Guess:",guess
  10.     p = False
  11.     while not p:
  12.         p = True
  13.         v = str(raw_input("Is my guess high, low, or correct (h/l/c): "))
  14.         if v[0] == 'h':
  15.             h = guess
  16.         elif v[0] == 'l':
  17.             l = guess
  18.         elif v[0] == 'c':
  19.             won = True
  20.         else:
  21.             print "Enter h, l, or c please"
  22.             p = False
  23. print "I won in",guesses,"guesses"
Advertisement
Add Comment
Please, Sign In to add comment