Skip to content

Instantly share code, notes, and snippets.

@gauravpatt92
Created May 6, 2017 22:24
Show Gist options
  • Save gauravpatt92/45937fb7f89d701b703a51b603c70c45 to your computer and use it in GitHub Desktop.
Save gauravpatt92/45937fb7f89d701b703a51b603c70c45 to your computer and use it in GitHub Desktop.
Python 3 code for guessing game 2 on practiceputhon.org
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