Reputation: 305
I need to use turtle library in Python in VS code. When I try to run my code:
import turtle
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
Terminal:
turtle.forward(100)
AttributeError: module 'turtle' has no attribute 'forward'
I found that VS code is not so popular IDE for turtle in Python, but is there any solution?
Thanks
Upvotes: 1
Views: 4628
Reputation: 24
from turtle import Turtle
turtle = Turtle()
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
Upvotes: 0
Reputation: 809
You issue is that you are not initializing a turtle. You are trying to move the module.
This is how you initialize a turtle:
new_turtle = turtle.Turtle()
Applying this to your code should look like the following:
import turtle
new_turtle = turtle.Turtle()
new_turtle.forward(100)
new_turtle.left(90)
new_turtle.forward(100)
new_turtle.left(90)
new_turtle.forward(100)
new_turtle.left(90)
new_turtle.forward(100)
Let me know if this helps
Upvotes: 3
Reputation: 85
I have VS Code, and works this code. Try it to chose interpreter path, or update turtle, or install extention for python in VSCode, or reinstall Python. I hope I could help Good luck
Upvotes: -1