实验8 python库应用编程与体验

2022/6/15 1:22:35

本文主要是介绍实验8 python库应用编程与体验,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

task3

 1 from turtle import *
 2 
 3 def square(size=50, rgb='gold'):
 4     '''绘制正方形
 5     参数size指定边长
 6     参数rgb指定画笔颜色
 7     如果没有给参数,采用默认值
 8     '''
 9     pencolor(rgb)
10     for i in range(4):
11         fd(size)
12         left(90)
13 
14 
15 def main():
16     setup(800, 600)
17     speed(0)
18 
19     n = 10
20     for i in range(n):
21         square(80)
22         left(360/n)
23 
24     hideturtle()
25     done()
26 
27 
28 if __name__ == '__main__':
29     main()

 

 

task4

 1 from turtle import *
 2 
 3 setup(800, 600)
 4 pencolor('pink')
 5 
 6 n = 10
 7 for i in range(n):
 8     # 绘制一片花瓣
 9     for j in range(2):
10         circle(80, 90)
11         left(90)
12 
13     right(360/n)
14 
15 hideturtle()
16 done()

 

 

task5

 1 from turtle import *
 2 
 3 setup(800, 600)
 4 bgcolor('black')
 5 pencolor('white')
 6 speed(0)
 7 
 8 angle = 0
 9 size = 2
10 
11 n = 10
12 for i in range(n):
13     for j in range(4):
14         fd(size)
15         angle += 72
16         seth(angle)
17         size += 5
18 
19 hideturtle()
20 done()

 

 

task6

 1 from turtle import*
 2 from random import random
 3 speed(0)
 4 def rect(x=10,y=50,rgb='black'):
 5     rgb=tuple(random() for i in range(3))
 6     color(rgb)
 7     for i in range(1,5):
 8         if i%2==1:
 9             fd(20)
10         else:
11             fd(50)
12         lt(90)
13 q=-150
14 for i in range(20):
15     penup()
16     goto(q,-10)
17     pendown()
18     fd(20)
19     left(90)
20     fd(50)
21     left(90)
22     fd(20)
23     left(90)
24     fd(50)
25     left(90)
26 
27     rgb = tuple(random() for i in range(3))
28     color(rgb)
29     begin_fill()
30     rect(20,50,rgb)
31     end_fill()
32     q += 20
33 
34 
35 ht()
36 done()

 



这篇关于实验8 python库应用编程与体验的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程