Advertisement
Guest User

Number Guesser

a guest
Apr 4th, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. lower_bound = 0
  2. upper_bound = 100
  3. guess = int((upper_bound + lower_bound) / 2)
  4. secret_number = ""
  5. answer = ""
  6.  
  7. print("Please think of a number between", lower_bound, "and", upper_bound)
  8. print("Is your secret number", guess, "?")
  9. while answer != "c":
  10.     answer = input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
  11.     if answer == "h":
  12.         upper_bound = guess
  13.         guess = int((upper_bound + lower_bound) / 2)
  14.         print("Is your secret number", guess, "?")
  15.     elif answer == "l":
  16.         lower_bound = guess
  17.         guess = int((upper_bound + lower_bound) / 2)
  18.         print("Is your secret number", guess, "?")
  19.     elif answer == "c":
  20.         print("Game over. Your secret number was:", guess)
  21.     else:
  22.         print("Sorry, I did not understand your input")
  23.         print("Is your secret number", guess, "?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement