# Magic 8-Ball

Hi everyone! I’m a bit stuck with this exercise. Whenever I run the code, I get ‘Error’ for ‘Magic 8-Ball’s Answer’ and not any of the randomly generated answers. I’ve looked at the code carefully and am not quite sure where I’m going wrong. Any help would be greatly appreciated!

Here is my code:

import random

name = "Rachael"

question = "Will it rain on Monday?"

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)

Here is the link to the exercise: Magic 8-Ball.

Hey and welcome to the forums!

Double check the values you are using for comparisons inside the if statement compared the the actual value of random_number. The values in the if statements are all strings, does this match what random_number actually is?

Hope that helps!

Thank you notlyall, that sorted it! Funny how you can miss little things like that when you’ve been looking at the same block of code for a while

1 Like

Haha yeah tell me about it, it’s the little bugs that can be the most annoying sometimes!