duquesne9

num guesser

Sep 5th, 2019
195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env python3
  2.  
  3.  
  4. # if anyone actually reads this, thank you for your work!!
  5.  
  6. epsilon = 1
  7. low = 0
  8. high = 100
  9. ans = ((low + high) // 2)
  10. num = 0
  11.  
  12.  
  13. def guess(answer, margin, bottom, top, number):
  14.     stop = False
  15.     while stop == False:
  16.         response = input(
  17.             "Is your secret number {}?\nEnter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. ".format(answer))
  18.         if response == 'l':
  19.             bottom = answer
  20.         elif response == 'h':
  21.             top = answer
  22.         elif response == 'c':
  23.             print("Game Over. Your secret number was:", end=' ')
  24.             print(answer)
  25.             stop = True
  26.             break
  27.         else:
  28.             print("I'm sorry, I did not understand your input.")
  29.             continue
  30.         answer = ((top + bottom) // 2)
  31.  
  32.  
  33. while not 100 > num > 0:
  34.     try:
  35.         num = int(input("Please think of a number between 0 and 100!"))
  36.     except ValueError:
  37.         print("not a valid input")
  38.         num = 0
  39.         continue
  40.  
  41. guess(ans, epsilon, low, high, num)
RAW Paste Data