Advertisement
brendan-stanford

num_guess

Aug 19th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. ## Guessing Game
  2.  
  3. print("Think of a number between 1 and 100")
  4.  
  5. #average function which determines the middle number the computer should guess next
  6. def min_max(minimum, maximum):
  7. mid = int((minimum + maximum)/2)
  8. return mid
  9.  
  10. #guess function which collects input from user to determine new guessing range
  11. def num_guess():
  12. guess = False
  13. max = 100
  14. min = 0
  15. count = 1
  16. while guess == False:
  17. middle = min_max(min, max)
  18. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  19. if answer == "H":
  20. min = middle
  21. count += 1
  22. elif answer == "L":
  23. max = middle
  24. count += 1
  25. else:
  26. print("Your number is {}, it took me ".format(middle) + str(count) + " guess(es)")
  27. guess = True
  28.  
  29. num_guess()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement