Advertisement
Guest User

Magic 8 Ball

a guest
Nov 12th, 2014
1,546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. # [Project] Magic 8 Ball
  2. # I'm sure you've used a magic 8 ball at one point in your life. You ask it a
  3. # question, turn it right side up and it gives an answer by way of a floating
  4. # die with responses written on it. You can create one in python. You must:
  5. #   1. Allow the user to enter their question
  6. #   2. Display an in progress message( i.e. "thinking")
  7. #   3. Create 20 responses, and show a random response
  8. #   4. Allow the user to ask another question or quit
  9. #
  10. # Bonus Using whatever module you like, add a gui. Your gui must have:
  11. #   1. A box for users to enter the question
  12. #   2. At least 4 buttons: Ask , clear(the text box), play again and
  13. #      quit(this must close the window)
  14. import random
  15. import time
  16. import sys
  17.  
  18. # Variables
  19. QUESTION = "What is it that you wish to learn?"
  20. PROMPT = "> "
  21. PROGRESS_MSG = "Let us ask the fates..."
  22. RESPONSES = [
  23.     "It is certain",
  24.     "It is decidedly so",
  25.     "Without a doubt",
  26.     "Yes definitely",
  27.     "You may rely on it",
  28.     "As I see it, yes",
  29.     "Most likely",
  30.     "Outlook good",
  31.     "Yes",
  32.     "Signs point to yes" ,
  33.     "Reply hazy try again",
  34.     "Ask again later",
  35.     "Better not tell you now",
  36.     "Cannot predict now",
  37.     "Concentrate and ask again",
  38.     "Don't count on it",
  39.     "My reply is no",
  40.     "My sources say no",
  41.     "Outlook not so good",
  42.     "Very doubtful"]
  43. TRY_AGAIN = "Would you like to try again? (y/n)"
  44.  
  45.  
  46. # Functions
  47. def fortune():
  48.     print(QUESTION)
  49.     raw_input(PROMPT)
  50.     print(PROGRESS_MSG)
  51.     time.sleep(2)
  52.     print
  53.     print(random.choice(RESPONSES))
  54.     do_over()
  55.  
  56. def do_over():
  57.     print(TRY_AGAIN)
  58.     answer = raw_input(PROMPT)
  59.     if answer.strip()[0] == "y":
  60.         fortune()
  61.     else:
  62.         print("May the fates favor you!")
  63.         sys.exit(0)
  64.  
  65. # App
  66. print("=== MAGIC 8 BALL ===")
  67. fortune()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement