timpin

Untitled

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