[英]TypeError: start must be a integer
I am trying to draw five turtles, but I am getting a TypeError
on line 25. Here is my code: 我正在尝试绘制五只乌龟,但是在第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)
I am trying to draw five roses, but it produces errors. 我试图画五朵玫瑰,但是会产生错误。 I am doing this in interactivepython.org. 我在interactivepython.org中这样做。
You are recursively calling drawRose
with the wrong parameter. 您递归调用带有错误参数的drawRose
。 On the line 23 ( for i in range(red):
) you expect red
to be an integer, which is it, when first called on line 36 ( drawRose(50)
). 在第23行( for i in range(red):
),您期望red
是一个整数,即第一次在第36行( drawRose(50)
)调用时。 But then on line 27 ( drawRose(redrose)
) you are passing in the redrose
object, which is a turtle. 但是,然后在第27行( drawRose(redrose)
)中,您传入了redrose
对象,它是一只乌龟。 It is not clear to me exactly what you should pass in there. 我不清楚您应该在那里传递什么。 I doubt that you even want to call it recursively. 我怀疑您甚至想递归调用它。 I suspect you actually want another function like drawPetal
. 我怀疑您实际上是否想要另一个函数如drawPetal
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.