擅长:python、mysql、java
<p>尽管将<code>forward(int('triangle'))</code>更改为<code>forward(int(triangle))</code>是必要的,但这还不够,因为<code>bodylength</code>没有定义。让我们重做它以使代码更清晰并运行:</p>
<pre><code>from turtle import Turtle, Screen
import math
def triangle(turtle, bodylength):
distance = bodylength / 5 * 3 / 2 / math.cos(math.radians(70))
turtle.penup()
turtle.forward(bodylength / 5)
turtle.pendown()
turtle.left(70)
turtle.forward(distance)
turtle.right(140)
turtle.forward(distance)
turtle.forward(bodylength / 5)
screen = Screen()
yertle = Turtle()
triangle(yertle, int(input("Body length: ")))
screen.exitonclick() # depending on the environment, you may not need this
</code></pre>