Created
May 6, 2017 22:24
-
-
Save gauravpatt92/45937fb7f89d701b703a51b603c70c45 to your computer and use it in GitHub Desktop.
Python 3 code for guessing game 2 on practiceputhon.org
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
def guess_work(): | |
count = 0 | |
min = 0 | |
max = 101 | |
ans = "" | |
while ans!='same': | |
count+=1 | |
mid = (max + min)//2 | |
ans = input("My guess is %s. Is that high, low or same? "%(mid)) | |
if ans=='high': | |
max = mid | |
if ans=='low': | |
min = mid | |
if ans=="": | |
return 50 | |
else: | |
print ("Congrats to me! I guessed it in %s tries."%(count)) | |
if __name__=="__main__": | |
print("Guess a number between 0 and 100 and tell whether high or low when prompted!") | |
guess_work() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment