Skip to content

Instantly share code, notes, and snippets.

@Mimie-15
Created December 7, 2021 05:35
Show Gist options
  • Save Mimie-15/d7a03cdf8a2574218afb254e704c4bd5 to your computer and use it in GitHub Desktop.
Save Mimie-15/d7a03cdf8a2574218afb254e704c4bd5 to your computer and use it in GitHub Desktop.
working with control flow
LEARN PYTHON 3
Magic 8-Ball
The Magic 8-Ball is a popular toy developed in the 1950s for fortune-telling or advice seeking.
Write a magic8.py Python program that can answer any “Yes” or “No” question with a different fortune each time it executes.
Magic 8-Ball, should I do this project?
We’ll be using the following 9 possible answers for our Magic 8-Ball:
Yes - definitely.
It is decidedly so.
Without a doubt.
Reply hazy, try again.
Ask again later.
Better not tell you now.
My sources say no.
Outlook not so good.
Very doubtful.
import random
name = ""
question = "chomon will stop doing badthing with me"
answer = ""
random_number = random.randint(1, 11)
print(random_number)
if random_number == 1 :
answer="Yes - definitely."
elif random_number == 2 :
answer="It is decidedly so."
elif random_number == 3 :
answer="Without a doubt"
elif random_number == 4 :
answer="Reply hazy, try again."
elif random_number == 5 :
answer="Ask again later."
elif random_number == 6 :
answer="Better not tell you now."
elif random_number == 7 :
answer="My sources say no."
elif random_number == 8 :
answer="Outlook not so good."
elif random_number == 9 :
answer="Very doubtful."
elif random_number == 10 :
answer="no haha."
elif random_number == 11 :
answer="yes but.. uhh yes."
else:
"eror"
if name == "":
print("question: ",question)
else:
print(name,'asks: ')
print("Magic 8-Ball's answer:",answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment