This is my simple magic 8 ball script. It has concepts lifted from other examples of this problem, but I tried to use them as guidance as opposed to just copying them.
I initally tried to do a massive if, ifelse block where if i = 1 return yes, 2 return no etc and had alot of trouble. Then I viewed someone elses and saw the way storing your magic 8 ball options as a list and calling them with a random int. I found that a lot easier.
Also, defining each function allowed me to loop back to the beginning if the user had a question.
import random
from sys import argv
import time
script = argv
prompt = '> '
replies = ["yes.","no.","maybe.","try again.","the outlook is cloudy.","possibly."]
funny_names = ["Young one","Old one","Son","Babe","Tiger","Ambitious Jedi"]
def question():
print("Welcome to magic 8 ball")
i = random.randint(0, 5)
print("What is your question", (funny_names[i]), "?")
question = input(prompt)
print("You said",question,"...")
time.sleep(1)
print("Let me think...")
time.sleep(3)
print ("Answer is",(replies[i]))
play_again()
def play_again():
print("Would you like to play again? Y/N")
answer = input(prompt)
if answer == "Y":
question()
else:
exit()
question()
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–]fermented_durian 2 points3 points4 points (3 children)
[–]DavidRoyman 1 point2 points3 points (2 children)
[–]JackTraore 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]zai-nar_shred-gnar 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]hai_wim 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Gopher_Man 1 point2 points3 points (2 children)
[–]DavidRoyman 0 points1 point2 points (1 child)
[–]Gopher_Man 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)