Guest User

Untitled

a guest
Jul 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import math
  2.  
  3. upper_boundary = 101
  4. lower_boundary = 0
  5. guess = int(((upper_boundary - 1 ) + lower_boundary) / 2)
  6. counter = 1
  7.  
  8. input("Think of a number between 0 and 100 and click any key to continue... ")
  9.  
  10. print("Is your number " + str(guess) + "?")
  11. answer = input("y/n?: ")
  12. while answer == "n":
  13. previous_guess = guess
  14. print("Is the number smaller than " + str(guess) + "?")
  15. compare = input("y/n?: ")
  16. if compare == "y":
  17. upper_boundary = guess
  18. guess = int(math.ceil(((lower_boundary + upper_boundary) / 2)))
  19. else:
  20. lower_boundary = guess
  21. guess = int(math.floor(((lower_boundary + upper_boundary) / 2)))
  22. print("Is your number " + str(guess) + "?")
  23. counter += 1
  24. answer = input("y/n?: ")
  25. if guess == previous_guess:
  26. answer = "y"
  27. counter -= 1
  28. print("It actually must be or you are cheating!")
  29.  
  30. print("Gotcha! Your imagined number: " + str(guess))
  31. print("Amount of guesses it took this PC: " + str(counter))
Add Comment
Please, Sign In to add comment