 # Help with the Magic 8 ball exercise

Hello everyone!
My first time posting here so I apologize in advance if it’s in the wrong place.

I am currently working through the python 3 courses and I’m on the Magic 8 ball section.
I have gone through it too many times and When I click save/run nothing happens Any advice on what I can do to make it work properly.

import random

name = “Ross”

question = “Why isn’t this working?”

random_number random.randint(1, 9)

if random_number == 1:

elif random_number == 2:

answer = “It is decidedly so”

elif random_number == 3:

elif random_number == 4:

elif random_number == 5:

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:

else:

print(name + " asks: " + question)

paste your code here like this below with three back quotation marks at the start and end, as here the indentation cannot be seen

triple back quotations

code/program

triple back quotations

///

import random

name = “Ross”
question = “Why isn’t this working?”
random_number random.randint(1, 9)

if random_number == 1:
elif random_number == 2:
answer = “It is decidedly so”
elif random_number == 3:
elif random_number == 4:
elif random_number == 5:
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:
else:

print(name + " asks: " + question)

///

Hey Woodall132,

``````import random

name = "Ross"
question = "Why isn't this working?"
# You were missing an equal sign here.
# You need to set 'random_number'  equal to random.randint(1, 9).
random_number = random.randint(1, 9)

if random_number == 1:
elif random_number == 2:
answer = "It is decidedly so"
elif random_number == 3:
elif random_number == 4:
elif random_number == 5:
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:
else:

# Indent our print statements to the left.
print(name + " asks: " + question)

``````

So, set ‘random_number’ equal to random.randint(1, 9), indent your print statements to the left, and you should be good - Hope this helps!

1 Like

Ahhhh thank you very much! I’ve been racking my brain yet it was such a simple error. Thanks