Https://www.codecademy.com/courses/learn-python-3/projects/python-magic-8-ball

Hello, I am stuck on this exercise, I got stuck on step number 8, where it asks to assign a error to a string, this is what I have so far.

import random

name = “Patrick”

question = “Is Mayonaise an instrument?”

answer = “”

random.randint(1, 9)

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."

else:

answer = "Error"

I am not sure what I did wrong but I get this code message:

Traceback (most recent call last):
File “magic8.py”, line 11, in
print(random_number)
NameError: name ‘random_number’ is not defined

What do I do?

Remember to assign this to random_number.

I forgot how to assign certain things to others, how do I do that?

1 Like
random_number = random.randint(1, 8)
# variable    ^  value or expression
#             |
#         assignment
#          operator

Assignment is always right to left.