Python file won't run in Codecademy workspace

Hi, I’m trying to write a very simple random generator to choose between three movie suggestions.

This is my code:

import random

chosen_movie = random.randint(1,3)

if chosen_movie == 1:
    print("Rimini")
elif chosen_movie == 2:
    print("Wien retour")
elif chosen_movie == 3:
    print("Petit Maman")

I originally wanted to use the Codecademy workspace for this, but got this error:

"python3: can't open file 'random': [Errno 2] No such file or directory"

The code runs fine (as far as I can tell lol) in VScode and on a random online python compiler I googled quickly, though.

I’ve tried googling and searching the forum but haven’t found an explanation (at least not one I understand), so could anybody help me out what seems to be the problem here? Apologies if this has been asked before.

Thank you so much!

Hello!

I’ve also tried running your code in a Codecademy workspace and it works just fine, without any sign of that error which is a little odd if it did not work for you, would you mind sharing a link to the workspace please?

Here you go: https://www.codecademy.com/workspaces/6256c4501cbc9cff3f829def

1 Like

Thanks!

So I’ve tested that with a couple different filenames (see my workspace for it here: https://www.codecademy.com/workspaces/6256d14a7a3ec2981110fc30) and I believe it’s caused by having random and spaces in the filename, since imports can be used to import files not just modules, so that name is causing a conflict, try renaming it to something else or (even better) add _ instead of spaces into the filename, as you generally don’t want to have spaces in paths :slight_smile:

1 Like

Aaaah thank you changing the name seems to be the solution! Thank you for the swift answer! I’ll try to remember this for the future :slight_smile:

1 Like