name 'turtle' is not defined on line 4 in main.py

混江龙づ霸主 提交于 2021-01-05 07:16:47

问题


Sorry for dumb question, new to python. I have the following code, running python 3.7:

from turtle import *
color('blue', 'red')
turtle.pu()
turtle.goto(0,0)
turtle.pd()
begin_fill()
forward(55)
left(90)
forward(110)

When I click run, it says I have an error on line three and four, but I can't figure out what's wrong. I tried searching everywhere but I can't find anything that helps me figure out what I did wrong.


回答1:


You need to create an instance of a Turtle object to use it

from turtle import *

bob = Turtle()
color('blue', 'red')
bob.pu()
bob.goto(0,0)
bob.pd()
begin_fill()
forward(55)
left(90)
forward(110)


来源:https://stackoverflow.com/questions/51988690/name-turtle-is-not-defined-on-line-4-in-main-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!