SHARE
TWEET

Untitled

a guest Aug 17th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print("Think of a number between 1 and 100, both inclusive.")
  2. def guess(min, max):
  3.   count = 0   # if I begin at 1, it adds a guess to the total number of guesses
  4.   while True:
  5.     middle = int((max + min)/2)
  6. # with upper, the user can use lower and capital letters
  7.     count = count + 1
  8.     answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}? ".format(middle)).upper()
  9.     if answer == "H":
  10.       min = middle
  11.     elif answer == "L":
  12.       max = middle
  13.     else:
  14. # if I include str(count) in the print, the format function goes crazy and mixes the numbers
  15.       print("Your number is {}, it took me {} guesses".format(middle, count))
  16.       quit()
  17.  
  18. guess(0, 101)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top