Python乌龟用三个参数画出一条脂肪线

2024-05-20 09:10:38 发布

您现在位置:Python中文网/ 问答频道 /正文

Write a function named fatLine(). The function fatLine() takes three parameters:

  1. a turtle, t
  2. an integer, segments, that is the number of segments in the line that is drawn
  3. an integer, increment, that is how much wider each successive segment of the line is

The function fatLine() should use the turtle t to draw a line composed of connected segments. Each segment should be of length 50. The width of the first line segment should be (the parameter) increment, and each successive segment should be wider than the preceding segment by increment. For example, if segments = 5 and increment = 10, the following is correct output

我试着用三个参数来编写这个代码,但我不确定如何才能运行它。任何帮助都很好谢谢。 我正试图将此代码编码为idle,但我没有运气。请帮助您了解如何执行。在


Tags: oftheanthatislinesegmentfunction
1条回答
网友
1楼 · 发布于 2024-05-20 09:10:38

既然已经过去五年了,这个问题,尽管没有显示出编码的努力,但它应该有一个答案:

from turtle import Screen, Turtle

def fatLine(t, segments, increment):
    width = increment

    for _ in range(segments):
        t.width(width)
        t.forward(50)
        width += increment

screen = Screen()
turtle = Turtle(visible=False)

turtle.penup()
turtle.backward(200)
turtle.pendown()

fatLine(turtle, 8, 10)

screen.exitonclick()

enter image description here

相关问题 更多 >