Turtle代码不起作用,显示py-lint没有成员错误

时间:2019-11-01 22:19:44

标签: python turtle-graphics

我相信我已经正确编码了所有代码,但是我不断收到一条错误消息,例如(“模块'turtle'没有'reset'成员)

import turtle

color = input('Enter a color:')

while (color != "QUIT"):
    turtle.reset()
    turtle.pencolor(color)
    turtle.pensize(10)

n = int(input('Enter a number:'))

if n % 3 == 0 and n % 5 == 0:
    turtle.penup()
    turtle.setposition(x=0, y=150)
    turtle.pendown()
    drawU(turtle.Turtle)
    turtle.penup()
    turtle.setposition(x = 0, y = -10)
    turtle.pendown()
    drawH(t)
elif n % 3 == 0:
    turtle.penup()
    turtle.setposition(x=0, y=150)
    turtle.pendown()
    drawU(turtle.Turtle)
elif n % 5 == 0:
    turtle.penup()
    turtle.setposition(x=0, y=150)
    turtle.pendown()
    drawH(turtle.Turtle)
else:
    turtle.pencolor('black')



def drawU (t):
    turtle.setheading(270)
    turtle.forward(150)
    turtle.left(90)
    turtle.forward(75)
    turtle.left(90)
    turtle.forward(150)

每个“ turtle .____”显示为错误。我不太确定自己在做什么错。我也在末尾添加了turtle.done(),这只是我代码的一半。

1 个答案:

答案 0 :(得分:0)

  

我相信我已经正确编码了所有内容

相距甚远:循环的终止取决于color的值,该值在循环期间永不改变;您应该在这里drawU(turtle.Turtle)传递乌龟 instance ,但要传递乌龟 class ;您的else子句毫无意义,实际上是无操作;您显示的缩进不起作用;您的drawH()函数丢失。

以下是我尝试重建您想要的代码的尝试,但我不确定:

from turtle import Screen, Turtle

def drawU(turtle):
    turtle.setheading(270)
    turtle.forward(150)
    turtle.left(90)
    turtle.forward(75)
    turtle.left(90)
    turtle.forward(150)

def drawH(turtle):
    pass

color = input('Enter a color: ')

screen = Screen()
turtle = Turtle()

while color != "QUIT":

    n = int(input('Enter a number: '))

    turtle.reset()
    turtle.pencolor(color)
    turtle.pensize(10)

    if n % 3 == 0 and n % 5 == 0:
        turtle.penup()
        turtle.setposition(x=0, y=150)
        turtle.pendown()
        drawU(turtle)
        turtle.penup()
        turtle.setposition(x=0, y=10)
        turtle.pendown()
        drawH(turtle)
    elif n % 3 == 0:
        turtle.penup()
        turtle.setposition(x=0, y=150)
        turtle.pendown()
        drawU(turtle)
    elif n % 5 == 0:
        turtle.penup()
        turtle.setposition(x=0, y=150)
        turtle.pendown()
        drawH(turtle)

    color = input('Enter a color: ')

screen.mainloop()