r/learnpython • u/hff22 • 4d ago
Why wont this work?
The code works if IDLE python but when using visual studio code i keep getting "name 'randrange' is not defined" error anyone know why it doesn't work in visual studio?
from random import *
from turtle import *
forward(randrange(1, 10))
done()from random import *
from turtle import *
forward(randrange(1, 10))
done()
0
Upvotes
6
u/atarivcs 4d ago
Do you have your own python file named
random.py?2
u/lfdfq 4d ago
'Using' visual studio code, in what way? Is the message you see coming from running Python on the file? or something VS Code is showing you? or something else?
It's very hard to help, since the code works (you say so yourself). Maybe you aren't running the code you think, or did not save the file correctly, or are looking at the wrong file, or any number of other unrelated problems.
3
u/zanfar 4d ago
Don't use star imports. They don't import everything, which is probably your issue here.
Also, don't name files in your working directory the same as standard library packages.
1
u/HummingHamster 4d ago
Try explicit import, there might be issue with VS's in supporting wildcard import.