daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Guessing Game
  2. max = 101
  3. min = 0
  4. attempts = 1
  5. finished = False
  6.  
  7. def Guessed_it(middle, attempts):
  8.         print("Your number is {}".format(middle) + ". Number of guesses = " + str(attempts))
  9.  
  10. def Guess(min, max,finished, attempts):
  11.     while finished == False:
  12.             middle = int((max + min)/2)
  13.             answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  14.             if answer == "H":
  15.                 min = middle
  16.                 attempts = attempts + 1
  17.             elif answer == "L":
  18.                 max = middle
  19.                 attempts = attempts + 1
  20.             elif answer == "S":
  21.                 Guessed_it(middle, attempts)
  22.                 finished = True
  23.                 return finished
  24.             else:
  25.                 print("Invalid input, try again")
  26.                
  27. print("Think of a number between 1 and 100")
  28. Guess(min,max,finished, attempts)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top