Python Turtle Error In Visual Studio Code

Viewed 121

So i made a python turtle thing a while ago and it worked just fine. However, when i try to run it now it doesnt work. Here is the code:

import turtle
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.exitonclick()

It gives a error saying:

Exception has occurred: AttributeError module 'turtle' has no attribute 'forward' File "C:\Users\melek büyük\Desktop\Programlama\Python\ptrh.py", line 2, in turtle.forward(100)"

It didn't do this before. Can someone please help me?

2 Answers

Seems like your file might be called turtle or you have another file called turtle. This would cause the import to not actual import the turtle library, so you should rename the file.

I guess you forgot to initialize a new object like this:

import turtle

your_turtle = turtle.Turtle()

# And then you can start drawing

your_turtle.forward(100)
your_turtle.right(144)
your_turtle.forward(100)
your_turtle.right(144)
your_turtle.forward(100)

# ...
Related