python 第二周练习作业

一、画五角星

 

描述

 

画一个五角星,画笔用黄色,用红色填充,效果如下所示。 ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

 

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#画五角星
import turtle
turtle.pensize(5)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()
for in range(5):
    turtle.forward(120)
    turtle.right(144)
    turtle.forward(120)
    turtle.left(72)
turtle.end_fill()
turtle.hideturtle()   #隐藏画笔
turtle.done()         #结束绘制

 

 

二、画一组同心圆

 

描述

利用turtle库画一组同心圆。用户输入最小圆的半径、圆的个数和画笔颜色,每个相邻圆半径相差20。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

 ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

输入格式

第一行输入一个正整数,作为最小圆的半径‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

第二行输入一个正整数,作为圆的个数‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

第三行输入画笔颜色的英文名,如red, blue, green等‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

 

输出格式

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#画一组同心圆
rmin=eval(input())
number=eval(input())
color=input()
import turtle as t
t.pencolor(color)
t.pensize(4)
for in range (number):
    t.circle(rmin)
    rmin=rmin+20
    t.penup()
    t.seth(-90)
    t.fd(20)
    t.seth(0)
    t.pendown()
t.hideturtle()
t.done()

  输入:

50
5
pink

 

三、渐变的圆

描述

利用turtle库的circle(50)函数可以画半径为50的圆,circle(50,steps=n)可以画半径为50的圆的内接正n边形,利用这个方法绘制示例中的图形,设置画笔为蓝色并用黄色填充图形。n由用户输入,要求n>=3且小于10。(注意:最后一个必须是圆,不能是正多边形)‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

 ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

输入格式

一个大于等于3且小于10的正整数‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

输出格式

 ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬

 

代码如下:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#渐变的圆
import turtle
 
number = int(input())      #把用户输入转成整数
turtle.screensize(600,500,'white')
turtle.pensize(3)           #设置画笔宽度为3
turtle.pencolor('blue')    #设置画笔颜色为黑色
turtle.fillcolor('yellow')  #设置填充颜色为黄色
turtle.begin_fill()         #开始填充
turtle.forward(-50)
 
for in range(3,number):
    turtle.circle(50, steps=i)
    turtle.forward(100)
turtle.circle(50, steps=number)
if number == 1:
    turtle.circle(50)
else:
    turtle.forward(100)
    turtle.circle(50)
turtle.end_fill()
turtle.hideturtle()         #隐藏海龟
turtle.done()

  输入:

9

 

五、画太极图

描述

利用turtle库画以下太极图形状.

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#绘制太极图
from turtle import *
setup(800,800,100,100)
 
#绘制左半部分
fillcolor('#FFFFFF')
begin_fill()
circle(100,180)
circle(200,180)
seth(180)
circle(-100,180)
end_fill()
seth(90)
penup()
fd(85)
pendown()
seth(0)
fillcolor('#000000')
begin_fill()
circle(25)
end_fill()
seth(-90)
penup()
fd(85)
pendown()
seth(180)
 
#绘制右半部分
fillcolor('#000000')
begin_fill()
circle(100,180)
circle(200,180)
seth(0)
circle(-100,180)
end_fill()
seth(-90)
penup()
fd(85)
pendown()
seth(-180)
fillcolor('#FFFFFF')
begin_fill()
circle(25)
end_fill()
hideturtle()
done()

posted @ 2020-03-19 15:35  翁剑波  阅读(1249)  评论(0)    收藏  举报