题目
根据表中的命令提示,阅读以下Python程序段,描述程序实现的过程。
命令
说明
turtle.forward(distance)
向当前画笔方向移动distance像素长度
turtle.backward(distance)
向当前画笔相反方向移动distance像素长度
turtle.right(degree)
顺时针移动degree°
turtle.left(degree)
逆时针移动degree
turtle.pencolor()
返回当前画笔颜色,传人参数设置画笔颜色
import turtle
t=turtle. pen()
turtle. bgcolor("white*")
colors=["red","green" "blue"]
for x in range(3):
turtle. pencolor(colors[x%3])
turtle. eft(120)
turtle. forward(150)
答案:解:程序主要分两步:第一步,初始化画布,将背景置成白色;第二步,绘制图形。画笔逆时针旋转120度, 画一条150mm长的线条;然后变为绿色,再旋转120度,画一条150mm长的线条;最后变为蓝色,再旋转120度,画-一条150mm长的线条,可得到等边三角形。