Last active
October 5, 2017 15:37
-
-
Save AO8/3863d138d34484f9be8e8ba6b896bd71 to your computer and use it in GitHub Desktop.
Magic 8 Ball with Python. Reads from included txt file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["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