Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement