Guest User

Untitled

a guest
Jun 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import random
  2. from time import sleep
  3. def intro():
  4. print("In this game, you have to choose a number between 0 and 100.\nThe computer will then try to guess the number in as few attempts as possible.\nYou will have too help the computer a bit by saying whether the guess was correct, too low, or too high.\n")
  5. sleep(3)
  6. def understanding():
  7. q = str(input("Do you think that you understand everything and are ready to begin the game? Please answer 'Yes' or 'No': "))
  8. q = q.lower()
  9. if (q == "yes" or q == "y"):
  10. return print("Coolio. Now think of a number and make sure you remember it."), sleep(3)
  11. elif (q == "no" or q == "n"):
  12. return print("Maybe read the instructions again.\n"), intro(), understanding()
  13. else:
  14. return print("You must have mistyped your answer. We forgive you. Please try again"), understanding()
  15.  
  16. def number():
  17. n = random.randint(0, 100)
  18. print("Computer is guessing number: ", n)
  19. return n
  20.  
  21. def game():
  22. attempt = 0
  23. num = number()
  24. quest = input("Is the number above the number you picked? you picked? Please answer 'Yes' or 'No': ")
  25. quest = quest.lower()
  26. if (quest == "y" or quest == "yes"):
  27. attempt = attempt + 1
  28. return print("Incredible. It only took", attempt," attempt!")
  29. elif (quest == "n" or quest == "no"):
  30. while quest != "yes":
  31. question = input("Was the computer's guess too low or too high?\n")
  32. question = question.lower()
  33. if question == "too low":
  34. attempt = attempt + 1
  35. num = ((100 - num) * 0.5 ) + num
  36. num = int(num)
  37. if num > 98:
  38. num = 100
  39. print(num)
  40. elif question == "too high":
  41. attempt = attempt + 1
  42. num = num - ((100 - num) * 0.5)
  43. num = int(num)
  44. print(num)
  45. else:
  46. print("Please make sure that you answer either 'too high' or 'too low'. Thank you.\n")
  47. quest = input("\nIs the number above the number you have chosen? Please answer 'Yes' or 'No': ")
  48. quest = quest.lower()
  49. attempt = attempt + 1
  50. return print("It took some time but we are finally there. It took", attempt," attempts.")
  51. else:
  52. print("Please answer either 'Yes' or 'No'."), game()
  53.  
  54. intro()
  55. understanding()
  56. game()
Add Comment
Please, Sign In to add comment