Advertisement
tartanberti

guessing_game_function

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