Sorry for dumb question, i’m new to python
What i’ve writed in code:
import time
from random import randint
from turtle import *
while True:
if randint(1,2) == 1:
forward(randint(20,100))
else:
backward(randint(20,100))
if randint(1,2) == 1:
right(randint(20,100))
else:
left(randint(20,100))
What i’ve got in output:
File "C:\Users\amogus\Desktop\python\turtle.py", line 4, in <module>
from turtle import *
File "C:\Users\amogus\Desktop\python\turtle.py", line 7, in <module>
forward(randint(20,100))
NameError: name 'forward' is not defined
Can someone help with this?
>Solution :
Your python file is named turtle.py, so when you type from turtle import * it attempts to import everything from itself, and since there’s nothing defined yet, it’s essentially a no-op (i.e. doing nothing).
Rename your python file to anything but turtle.py and it should work.