def evaluate(number):
print "Is your number %d? (Yes: 'Y', Higher: 'H', Lower: 'L')" % number
valid_answers = 'Y', 'H', 'L'
while True:
answer = raw_input("> ")
if answer.upper() in valid_answers:
return answer.upper()
else:
print "Invalid input, try again..."
print """Hello, pick a number so we can play a game of me trying to guess it.
Don't you dare cheating pal, I'll cut you! Now let's play!
When you are ready press ENTER
"""
raw_input()
max_number = max_guess = 100
min_number = min_guess = 1
tries = 0
wins = 0
while True:
guess = (min_guess + max_guess) / 2
tries += 1
result = evaluate(guess);
if result == 'Y':
print """
Hurray, I rule! I had to try %d times.
So far I have won %d games.
Wanna play again? (Y/N)
""" % (tries, wins)
wins += 1
play_again = raw_input("> ")
if play_again.upper() == 'Y':
max_guess = 100
min_guess = 1
tries = 0
else:
break
elif result == 'H':
min_guess = guess
else:
max_guess = guess