Day001第一天的第一个Python源程序

mac2025-08-13  3

昨天是学习python第一天,没有及时记录。现在补上昨天的成果,一个小小源程序如下:

程序: 绘制奥运五环图

步骤1、画出5个圆

#绘制奥运五环 import turtle turtle.circle(50) #画半径为50的圆 turtle.goto(120,0) #去坐标为(120,0)的点 turtle.circle(50) turtle.goto(240,0) turtle.circle(50) turtle.goto(60,-50) turtle.circle(50) turtle.goto(180,-50) turtle.circle(50)

运行结果:

步骤2、去掉多于线条

#绘制奥运五环 import turtle turtle.circle(50) #画半径为50的圆 turtle.penup() #抬笔 turtle.goto(120,0) #去坐标为(120,0)的点 turtle.pendown() #落笔 turtle.circle(50) turtle.penup() #抬笔 turtle.goto(240,0) turtle.pendown() #落笔 turtle.circle(50) turtle.penup() #抬笔 turtle.goto(60,-50) turtle.pendown() #落笔 turtle.circle(50) turtle.penup() #抬笔 turtle.goto(180,-50) turtle.pendown() #落笔 turtle.circle(50)

运行结果:

步骤3、调整线条粗细程度

#绘制奥运五环 import turtle turtle.width(10) #线条宽度设置为10 turtle.circle(50) #画半径为50的圆 turtle.penup() #抬笔 turtle.goto(120,0) #去坐标为(120,0)的点 turtle.pendown() #落笔 turtle.circle(50) turtle.penup() #抬笔 turtle.goto(240,0) turtle.pendown() #落笔 turtle.circle(50) turtle.penup() #抬笔 turtle.goto(60,-50) turtle.pendown() #落笔 turtle.circle(50) turtle.penup() #抬笔 turtle.goto(180,-50) turtle.pendown() #落笔 turtle.circle(50)

运行结果:

步骤4、分别设置每个圆的线条颜色

#绘制奥运五环 import turtle turtle.width(10) #线条宽度设置为10 turtle.color("blue") #线条颜色设置为“蓝色” turtle.circle(50) #画半径为50的圆 turtle.penup() #抬笔 turtle.goto(120,0) #去坐标为(120,0)的点 turtle.pendown() #落笔 turtle.color("black") #线条颜色设置为“黑色” turtle.circle(50) turtle.penup() #抬笔 turtle.goto(240,0) turtle.pendown() #落笔 turtle.color("red") turtle.circle(50) turtle.penup() #抬笔 turtle.goto(60,-50) turtle.pendown() #落笔 turtle.color("yellow") turtle.circle(50) turtle.penup() #抬笔 turtle.goto(180,-50) turtle.pendown() #落笔 turtle.color("green") turtle.circle(50)

运行结果:

第一个程序的分享就到此结束,虽然比起真正的奥运五环图还差着一些,但是对于我这个初学者来讲,不能要求太高啦。

最新回复(0)