VS 代码 Python 乌龟
VS Code Python turtle
我需要在 VS 代码中使用 Python 中的海龟库。当我尝试 运行 我的代码时:
import turtle
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
航站楼:
turtle.forward(100)
AttributeError: module 'turtle' has no attribute 'forward'
我发现VS code在Python中对于turtle并不那么流行IDE,但是有什么解决办法吗?
谢谢
我有 VS Code,可以使用这段代码。
尝试选择解释器路径,或更新 turtle,或在 VSCode 中安装 python 的扩展,或重新安装 Python。
我希望我能帮上忙
祝你好运
你的问题是你没有初始化海龟。您正在尝试移动模块。
这是初始化海龟的方式:
new_turtle = turtle.Turtle()
将此应用于您的代码应如下所示:
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)
如果有帮助请告诉我
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)
我需要在 VS 代码中使用 Python 中的海龟库。当我尝试 运行 我的代码时:
import turtle
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
航站楼:
turtle.forward(100)
AttributeError: module 'turtle' has no attribute 'forward'
我发现VS code在Python中对于turtle并不那么流行IDE,但是有什么解决办法吗?
谢谢
我有 VS Code,可以使用这段代码。 尝试选择解释器路径,或更新 turtle,或在 VSCode 中安装 python 的扩展,或重新安装 Python。 我希望我能帮上忙 祝你好运
你的问题是你没有初始化海龟。您正在尝试移动模块。
这是初始化海龟的方式:
new_turtle = turtle.Turtle()
将此应用于您的代码应如下所示:
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)
如果有帮助请告诉我
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)