Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement