Created
June 27, 2018 13:25
-
-
Save hta218/2dcc3e492b031e48cea9b4d99a50a652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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