Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # [Project] Magic 8 Ball
- # I'm sure you've used a magic 8 ball at one point in your life. You ask it a
- # question, turn it right side up and it gives an answer by way of a floating
- # die with responses written on it. You can create one in python. You must:
- # 1. Allow the user to enter their question
- # 2. Display an in progress message( i.e. "thinking")
- # 3. Create 20 responses, and show a random response
- # 4. Allow the user to ask another question or quit
- #
- # Bonus Using whatever module you like, add a gui. Your gui must have:
- # 1. A box for users to enter the question
- # 2. At least 4 buttons: Ask , clear(the text box), play again and
- # quit(this must close the window)
- import random
- import time
- import sys
- # Variables
- QUESTION = "What is it that you wish to learn?"
- PROMPT = "> "
- PROGRESS_MSG = "Let us ask the fates..."
- RESPONSES = [
- "It is certain",
- "It is decidedly so",
- "Without a doubt",
- "Yes definitely",
- "You may rely on it",
- "As I see it, yes",
- "Most likely",
- "Outlook good",
- "Yes",
- "Signs point to yes" ,
- "Reply hazy try again",
- "Ask again later",
- "Better not tell you now",
- "Cannot predict now",
- "Concentrate and ask again",
- "Don't count on it",
- "My reply is no",
- "My sources say no",
- "Outlook not so good",
- "Very doubtful"]
- TRY_AGAIN = "Would you like to try again? (y/n)"
- # Functions
- def fortune():
- print(QUESTION)
- raw_input(PROMPT)
- print(PROGRESS_MSG)
- time.sleep(2)
- print
- print(random.choice(RESPONSES))
- do_over()
- def do_over():
- print(TRY_AGAIN)
- answer = raw_input(PROMPT)
- if answer.strip()[0] == "y":
- fortune()
- else:
- print("May the fates favor you!")
- sys.exit(0)
- # App
- print("=== MAGIC 8 BALL ===")
- fortune()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement