Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from time import sleep
- def intro():
- 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")
- sleep(3)
- def understanding():
- q = str(input("Do you think that you understand everything and are ready to begin the game? Please answer 'Yes' or 'No': "))
- q = q.lower()
- if (q == "yes" or q == "y"):
- return print("Coolio. Now think of a number and make sure you remember it."), sleep(3)
- elif (q == "no" or q == "n"):
- return print("Maybe read the instructions again.\n"), intro(), understanding()
- else:
- return print("You must have mistyped your answer. We forgive you. Please try again"), understanding()
- def number():
- n = random.randint(0, 100)
- print("Computer is guessing number: ", n)
- return n
- def game():
- attempt = 0
- num = number()
- quest = input("Is the number above the number you picked? you picked? Please answer 'Yes' or 'No': ")
- quest = quest.lower()
- if (quest == "y" or quest == "yes"):
- attempt = attempt + 1
- return print("Incredible. It only took", attempt," attempt!")
- elif (quest == "n" or quest == "no"):
- while quest != "yes":
- question = input("Was the computer's guess too low or too high?\n")
- question = question.lower()
- if question == "too low":
- attempt = attempt + 1
- num = ((100 - num) * 0.5 ) + num
- num = int(num)
- if num > 98:
- num = 100
- print(num)
- elif question == "too high":
- attempt = attempt + 1
- num = num - ((100 - num) * 0.5)
- num = int(num)
- print(num)
- else:
- print("Please make sure that you answer either 'too high' or 'too low'. Thank you.\n")
- quest = input("\nIs the number above the number you have chosen? Please answer 'Yes' or 'No': ")
- quest = quest.lower()
- attempt = attempt + 1
- return print("It took some time but we are finally there. It took", attempt," attempts.")
- else:
- print("Please answer either 'Yes' or 'No'."), game()
- intro()
- understanding()
- game()
Add Comment
Please, Sign In to add comment