#第二题
import turtle as t
angles=[0,90,180,270]
colors=["red","yellow","blue","green"]
y=0
for x in angles:
t.setheading(x)#画笔朝向,可简写为seth
t.fillcolor( colors[y] )#遍历colors的字符串
t.begin_fill()
t.fd(100)
t.rt(90)
t.circle(-100,45)#顺时针为负,45是角度
t.rt(90)
t.fd(100)
t.end_fill()
y+=1
改进一下,可以用一个变量x取代变量y
#更加简洁的写法
import turtle as t
#angles=[0,90,180,270]
colors=["red","yellow","blue","green"]
for x in range(4):
t.setheading(x*90)#画笔朝向,可简写为seth
t.fillcolor( colors[x] )
t.begin_fill()
t.fd(100)
t.rt(90)
t.circle(-100,45)#顺时针为负,45是角度
t.rt(90)
t.fd(100)
t.end_fill()
效果相同,但更加简便。