1.关于turtle库,请参考网页百度百科-验证,编译环境为pycharm.3.8
2代码部分
import turtle as t
n = int(input('请输入你想要输入N的值(3=<N<=10):'))
t.setup(1000,600)
t.penup()
t.goto(-350,0)
t.pendown()
t.pensize(2)
t.color("blue","yellow")
t.begin_fill()
for i in range(3,n):
t.circle(50, steps=i)
t.fd(100)
else:
t.circle(50)
t.end_fill()
t.hideturtle()
t.done()
3 .代码讲解
#导入turtle库,as 是重命名的意思,将turtle重命名为t,可以增加代码的简洁度,易于编写
import turtle as t
#输入你想要输入的值,python中输入默认为字符串,要强制转化为int类型,用百度百科-验证内置函数也可以
n = int(input('请输入你想要输入N的值(3=<N<=10):'))
#设置窗口的大小,默认为(400,300)
t.setup(1000,600)
#提起笔移动,不绘制图形,用于另起一个地方绘制(提起笔)
t.penup()
#将画笔移动到坐标为x,y的位置(找到你要落笔的位置)
t.goto(-350,0)
#将画笔移动时绘制图形,缺省时也为绘制(就是落笔的意思)
t.pendown()
#设置画笔的宽度为2
t.pensize(2)
#同时设置pencolor(画笔的颜色)=color1, fillcolor(填充的颜色)=color2
t.color("blue","yellow")
#准备开始填充图形
t.begin_fill()
#开始循环的打印图案
for i in range(3,n):
#设置圆的半径为50,圆的边为传入的参数i,
t.circle(50, steps=i)
#绘制完成后,将笔移动到下一次绘制的起点位置,准备绘制下一个图案
t.fd(100)
else:
t.circle(50)
#填充完成
t.end_fill()
#隐藏画笔(即隐藏海龟)
t.hideturtle()
#结束掉程序
t.done()
4 .核心的代码
for i in range(3,n):
t.circle(50, steps=i)
t.fd(100)