turtle案例之一:画自定义大小的奥运五环
描述
利用turtle库画奥运五环,圆半径为由用户输入,各圆的颜色按顺序取"red","blue","green","yellow","black"中的一种,效果如图所示。各圆绘制起点坐标可用以下语句获取:
coordA=(-2.2*radius,0,2.2*radius,-1.1*radius,1.1*radius)#各圆绘制起点坐标x值, radius为半径
coordB=(0,0,0,-1.1*radius,-1.1*radius) #各圆绘制起点坐标y值, radius为半径
turtle.goto(coordA[i],coordB[i])
答案
from turtle import*
radius=int(input())
colors=("red","blue","green","yellow","black")
for i in range(5):
penup()
coordA=(-2.2*radius,0,2.2*radius,-1.1*radius,1.1*radius)#各圆绘制起点坐标x值, radius为半径
coordB=(0,0,0,-1.1*radius,-1.1*radius) #各圆绘制起点坐标y值, radius为半径
goto(coordA[i],coordB[i])
pendown()
pencolor(colors[i])
circle(radius)
hideturtle()