二级 Python 简单应用题

高仿模拟练习,turtle 绘图与编程应用,答案点击按钮展开

136简单应用题:turtle 画水平三色块

画三个水平 120x40 的矩形,颜色依次红/黄/蓝,用 begin_fill/end_fill 填充。

import turtle
t = turtle.Turtle()
colors = ["red", "yellow", "blue"]
w, h = 120, 40
for i in range(3):
    t.____(colors[i])   # 设置颜色(笔画色和填充色同色)
    t.begin_fill()
    # 画矩形 4 边
    for j in range(2):
        t.forward(w); t.left(90); t.forward(h); t.left(90)
    t.____()   # 结束填充
    # 抬笔下移 h 画下一块
    t.penup(); t.goto(0, -(i+1)*h); t.pendown()
turtle.done()
参考答案
第一处: color
第二处: end_fill
解析

t.color(c) 一次设置画笔和填充色;begin_fill 包裹绘制,end_fill 完成填充。循环 3 次每次 goto(0, -(i+1)*h) 垂直下移一行。

试题及答案仅供练习参考,不保证完全准确,正式考试请以NCRE官方教材及官方内容为准。

©2026 NCRE二级题库 版权所有