Advertisement
kspatharas

guestgame

Mar 8th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. ## Guessing Game
  2.  
  3. max = 101
  4. min = 0
  5.  
  6. tries = 0
  7.  
  8. numFound = False
  9.  
  10. print("Think of a number between 1 and 100 ")
  11.  
  12. def middle (max , min):
  13.     return int((max + min)/2)
  14.    
  15. def findNum(max,min,tries):
  16.     temp = middle (max , min)
  17.     answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(temp))
  18.     if answer.upper() == "H":
  19.         min = middle (max , min)
  20.     elif answer.upper() == "L":
  21.         max = middle (max , min)
  22.     elif answer.upper() == "S":
  23.         return True , max , min , tries
  24.     else :
  25.         print("Invaled answer , answers must be 'H,L,S'")
  26.         return False , max , min , tries
  27.  
  28.    
  29.     tries=tries+1
  30.     return False , max , min , tries
  31.  
  32. while (numFound == False):
  33.     numFound, max , min , tries = findNum(max,min,tries)
  34.    
  35. print("Your number is {}, it took me {} guess".format(middle (max , min),tries))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement