Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Created March 28, 2019 19:44
Show Gist options
  • Select an option

  • Save topherPedersen/dadc28f42fa89d5aaaad127ea3b82c61 to your computer and use it in GitHub Desktop.

Select an option

Save topherPedersen/dadc28f42fa89d5aaaad127ea3b82c61 to your computer and use it in GitHub Desktop.
Magic 8 Ball for Python 3
# Magic 8 Ball by Chris Pedersen
# This is free and unencumbered software released into the public domain.
# For more information, please refer to <http://unlicense.org/>
import random
# Greet the User
print("Welcome to Magic 8 Ball!")
# Create Game Loop
keepPlaying = True
while keepPlaying == True:
# Prompt the User To Ask a Question
question = input("What is your question? ")
# Generate a Random Number Between 0 and 19
randomNumber = random.randint(0, 19)
# Create a List (or Array) of Fortunes
# (We Will Use These Fortunes to Answer Our User's Questions)
fortune = []
fortune.append("It is certain.")
fortune.append("It is decidedly so.")
fortune.append("Without a doubt.")
fortune.append("Yes - definitely.")
fortune.append("You may rely on it.")
fortune.append("As I see it, yes.")
fortune.append("Most likely.")
fortune.append("Outlook good.")
fortune.append("Yes.")
fortune.append("Signs point to yes.")
fortune.append("Reply hazy, try again.")
fortune.append("Ask again later.")
fortune.append("Better not tell you now.")
fortune.append("Cannot predict now.")
fortune.append("Concentrate and ask again.")
fortune.append("Don't count on it.")
fortune.append("My reply is no.")
fortune.append("My sources say no.")
fortune.append("Outlook not so good.")
fortune.append("Very doubtful.")
# Tell Fortune
print(fortune[randomNumber])
# Ask The User if He or She Would Like To Play Again
response = input("Would you like to ask Magic 8 Ball another question? Enter y for yes, n for no. ")
if response == "y":
keepPlaying = True
else:
keepPlaying = False
# End Game
print("Goodbye")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment