Skip to content

Instantly share code, notes, and snippets.

@hta218
Created June 27, 2018 13:25
Show Gist options
  • Save hta218/2dcc3e492b031e48cea9b4d99a50a652 to your computer and use it in GitHub Desktop.
Save hta218/2dcc3e492b031e48cea9b4d99a50a652 to your computer and use it in GitHub Desktop.
low = 1
high = 100
playing = True
print('Guess your number game')
input('Now think of a number from 1 to 100, then press Enter')
print("""
All you have to do is answer to my guess
'c' if my guess is correct
's' if my guess is 'S'maller than your number
'l' if my guess is 'L'arger than your number
""")
while playing:
mid = (low + high) // 2
answer = input('Is {0} your number? '.format(mid))
if answer.lower() == 'c':
print('I knew it!')
playing = False
elif answer.lower() == 's':
low = mid
elif answer.lower() == 'l':
high = mid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment