Advertisement
rickzman

Untitled

Dec 8th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. ## Guessing Game
  2.  
  3. max = 100
  4. min = 0
  5.  
  6.  
  7. def guess(max, min, count):
  8. middle = int((max + min)/2)
  9. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  10. if answer == "H":
  11. min = middle
  12. return(max, min)
  13. elif answer == "L":
  14. max = middle
  15. return(max, min)
  16. else:
  17. print("Your number is", middle, "it took me",count," guess".format(middle))
  18. quit()
  19.  
  20. print("Think of a number between 1 and 100")
  21.  
  22.  
  23. count =0
  24. while True:
  25. count = count + 1
  26. max, min = guess(max, min, count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement