Magic 8-ball project

Hi all. I’m currently working through the magic 8-ball project and could use a little guidance. Now the terminal is outputting a random number each run but no dialogue or anything else.

Okay so I am a little new to this but here is the code I have input so far:

import random

name = “Ramsey”

question = “Do socks REALLY go with sandals?”

answer = “”

random_number = random.randint(1, 9)


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


answer = “Error”

print(name + " asks: " + question)

print("Magic 8-Ball’s answer: " + answer)

and here is the link to the project :

Learn Python 3 | Codecademy

Any help is much appreciated!!

This code appears to be working for me completely fine both in VS Code and in the Codecademy environment. Check for any parts which may not be indented correctly, check that the Codecademy environment is working correctly also. If neither of the above is the problem, perhaps also post a screenshot of the code in the script, so we can see if there’s any specific issues not carried over to the forum post.

Okay so I have done some more investigating, and I have found the issue.


  answer = “Error”

  print(name + " asks: " + question)

  print("Magic 8-Ball’s answer: " + answer)

Just here you can see that the prints are indented into the else part. Therefore they will only run if there is an error. If you un-indent these then this should fix your issue.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.