Python 3.x AttributeError:“Turtle”对象没有属性“pencolour”
我是Python新手,有以下代码:Python 3.x AttributeError:“Turtle”对象没有属性“pencolour”,python-3.x,Python 3.x,我是Python新手,有以下代码: import turtle t = turtle.Pen() t.speed(0) colours = ["green", "blue", "dark purple", "grey"] for x in range(100): t.pencolour( colours[ x % 4] ) t.cirlce(2*x) t.left(91) 如果我尝试运行此代码,将出现以下错误: AttributeError:“Turtle”
import turtle
t = turtle.Pen()
t.speed(0)
colours = ["green", "blue", "dark purple", "grey"]
for x in range(100):
t.pencolour( colours[ x % 4] )
t.cirlce(2*x)
t.left(91)
如果我尝试运行此代码,将出现以下错误:
AttributeError:“Turtle”对象没有属性“pencolour”
如何修复此错误?如中所述,它是.pencolor,而不是.pencolor
这意味着你应该写:
t.pencolor( colours[ x % 4] )
而不是
t.pencolour( colours[ x % 4] )
在Python中,当您试图访问或调用某个特定对象类型不具备的属性时,通常会引发。
在您的示例中,您正在调用pencolor方法,但实现的方法称为pencolor