Hello,
I’m trying to follow the guidelines of the project for the Python3 course with their Magic 8-Ball program. Their problem statement wants us to provide a conditional output based on the presence/absence of parameters. My solution was to use indents to create a nested IF-ELSE statement, but it doesn’t seem to work.
import random
name = "Richard"
question = "Will I enjoy dinner tonight?"
answer = ""
random_number = random.randint(1,10)
if question == "":
"Please ask a question first."
else:
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 = "Why do you ask such a question?"
else:
answer = "Error"
if name == " ":
print("Question: " + question)
else:
print(name + " asks: " + question)
print("Magic 8-Ball's answer: " + answer)