crzcas

guessing game

Jan 7th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # guessing game, lesson 1.12
  2.  
  3. def guessing_game(min, max):
  4.  
  5.     print("Think of a number between " + str(min) + " and " + str(max))
  6.  
  7.     t = 0
  8.  
  9.     while t < max:
  10.  
  11.         middle = int((max + min)/2)
  12.         answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle) + " > ").upper()
  13.  
  14.         if answer == "H":
  15.             min = middle
  16.         elif answer == "L":
  17.             max = middle
  18.         else:
  19.             print("Your number is {}".format(middle) + ", it took me " + str(t + 1) + " guesses")
  20.             #quit()
  21.             break
  22.              
  23.         t = t + 1
  24.  
  25. guessing_game(0, 100)
Advertisement
Add Comment
Please, Sign In to add comment