小学生蓝桥杯Python闯关 | 绘制四叶风轮

449 阅读1分钟

学习Python从娃娃抓起!记录下蓝桥杯Python学习和备考过程中的题目,记录每一个瞬间。

附上汇总贴:小学生蓝桥杯Python闯关 | 汇总_COCOgsta的博客-CSDN博客


【题目描述】

在Turtle画布上画出如图所示的风轮,半径为100。要求:

  1. 风轮由4个扇叶组成,每个扇叶大小相等,相邻两个扇叶间距相等;
  2. 四个扇叶的颜色分别是('red', 'yellow', 'blue', 'green')

【代码详解】

import turtle as t
t.shape("turtle")
colors = ["red", "yellow", "blue", "green"]

def drawleave(x): #函数定义
    t.seth(x*90)
    t.fillcolor(colors[x])
    t.begin_fill()
    t.forward(100)
    t.right(90)
    t.circle(-100, 45)
    t.right(90)
    t.forward(100)
    t.end_fill()

for x in range(4):
    drawleave(x) #函数调用

t.done()

【运行结果】