Skip to content

Instantly share code, notes, and snippets.

@AO8
Last active October 5, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AO8/3863d138d34484f9be8e8ba6b896bd71 to your computer and use it in GitHub Desktop.
Save AO8/3863d138d34484f9be8e8ba6b896bd71 to your computer and use it in GitHub Desktop.
Magic 8 Ball with Python. Reads from included txt file.
import random
with open("eight_ball_answers.txt", "r") as f:
answers = f.read() # read in text as string
answers = answers.strip().replace('"', '') # remove white space and double quotes
answers = answers.strip('[]').split(', ') # remove the square brackets and split on separator
question = input("Ask a question or enter \"N\" to quit: ")
while not(question.upper().startswith("N")):
print(random.choice(answers))
question = input("\nAsk a question or enter \"N\" to quit: ")
["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"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment