我想画五只乌龟,但我在第25行得到TypeError
。这是我的代码:
import turtle
wn = turtle.Screen()
redrose = turtle.Turtle()
color = input("What will your background color be?")
fillcolor_f = input("What will the color of your rose be?")
redrose.hideturtle()
redrose.speed(30)
redrose.penup()
redrose.left(180)
redrose.forward(175)
redrose.right(90)
redrose.forward(30)
redrose.right(90)
redrose.pendown()
def drawRose(red):
redrose.color("pink")
redrose.fillcolor(fillcolor_f)
redrose.fill(True)
for i in range(red):
redrose.forward(i)
redrose.right(49)
for i in range(5):
drawRose(redrose)
redrose.penup()
redrose.forward(350)
redrose.right(144)
redrose.pendown()
redrose.fill(False)
drawRose(50)
wn.bgcolor(color)
我试图绘制五朵玫瑰,但它会产生错误。我在interactivepython.org中这样做。
答案 0 :(得分:2)
您使用错误的参数递归调用drawRose
。在第23行(for i in range(red):
)上,当第一次在第36行(red
)上调用时,您希望drawRose(50)
是一个整数。但是在第27行(drawRose(redrose)
)你传递的是redrose
对象,这是一只乌龟。我不清楚你应该在那里传递什么。我怀疑你甚至想要递归地调用它。我怀疑你真的想要另一个函数,如drawPetal
。