Python教程

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

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

task3

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

 

 

 

task4

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

 

 

 

task5

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

 

 

 

task6

 1 from random import random
 2 from turtle import *
 3 
 4 def rect():
 5     rgb = tuple(random() for i in range(3))
 6     color(rgb)
 7     begin_fill()
 8     for i in range(2):
 9         fd(20)
10         left(90)
11         fd(60)
12         left(90)
13     end_fill()
14     
15 def main():
16     goto(-11*20, 0)
17     for i in range(20):
18         rect()
19         fd(20)
20 
21 setup(800, 600)
22 speed(0)
23 main()

 

 

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