Advertisement
superpawko

W_02_C_03_E_03

Sep 21st, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. low = 0
  2. high = 100
  3. epsilon=1
  4. ans = abs(high - low) // 2
  5. check=''
  6. print("Please think of a number between 0 and 100!")
  7.  
  8. while ans > epsilon:
  9. print("Is your secret number " + str(ans) + "?")
  10. check = 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 check == 'c':
  12. print("Game over. Your secret number was: " + str(ans))
  13. break
  14. elif check == 'h':
  15. high = ans
  16. elif check == 'l':
  17. low = ans
  18. else:
  19. print("Sorry, I did not understand your input.")
  20. ans = (high + low) // 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement