Tried to replicate Magic 8 Ball on python - what am i doing wrong?

Maybe this is a dumb question… but I’m pretty new to all of this and I heard that it’s very important to have python installed on your computer so you can try out your new knowledge as you go.
I figured out the magic 8 ball project and decided to try and make my own version… didn’t work. Python came up with errors. I just figured I did something wrong and came here and copied the answer key to try instead… also wrong?

I really know nothing about coding and computers - I just love math and puzzles. Anyone able to help me out? I don’t even know if I’m using python correctly… :pensive:
here’s my version…

to make a condition for equality we use == not = so change these conditions from random_number = 1 to random_number == 1 and do that for elifs too.

also, change the last two lines to:

print(name, "wants to know", question)
print("Computer says", answer)

you should write your code in the file opened on the right side of your screenshot, and then click f5 or click run so the code will run in the left side window.

I highly encourage you to start learning coding seriously. you will really love the combination of creative and logical problem-solving skills you will use when writing code. So make some efforts to take your skills to the next level :boom:.


ahhhh thank you! fixed my mistakes - the biggest thing here is that I had no clue about hitting f5 …
Does Code Academy bother to teach us how to use the actual application? or just the programming? It is not intuitive for a newbie

1 Like

f5 isn’t a standard way to run codes it’s just relatable to the editor you are using, and there is a lot of editors you can use to write python.

Also, getting used to the editor isn’t hard just choose the one you think you are comfortable with. search for visual studio code or something bigger like Pycharm I think you will love them more than the one you are using.


You should be able to run this code line by line if you wanted. For some reason your first line wasn’t executed so it piled multiple statements together which doesn’t really work in the basic interactive interpreter (was this copy/pasted?).

I think you might have a better time with a slightly better interactive python interpreter (that does support multi-line statements) such as IPython or maybe use the notebooks- Project Jupyter | Installing the Jupyter Software if you wanted to annotate code further.

As @enghosamokasha mentions you could use a more advanced development environment too (command line versions are nice enough for quick tests but less useful for projects).

If you check the CC articles- and use the drop-down menu to select Python then you’ll see multiple articles about installing Python locally and setting up various tools but there are numerous online guides for the same if you’d prefer.


:exploding_head: thank you! I had no clue there were different editors. When I say I’m a newbie, I really mean it. I had no clue there were different editors! I’m going to download one tonight.
while we’re on the whole mind-blowing discovery theme… is there anything else you think I should know about? or like, is there a resource that you might recommend?

thank you - I’m going to check it out. I’ve got so much new information ahha I’m excited. I’ve got time to do this and I’m feeling determined to grow :smiling_face_with_three_hearts: