task1-1
1 from turtle import * 2 def move(x,y): 3 penup() 4 goto(x,y) 5 pendown() 6 7 def draw(n,size=100): 8 for i in range(n): 9 fd(size) 10 left(360/n) 11 def main(): 12 pensize(2) 13 pencolor('red') 14 15 move(-200,0) 16 draw(3) 17 18 move(0,0) 19 draw(4) 20 21 move(200,0) 22 draw(5) 23 24 hideturtle() 25 done() 26 27 main()
task1-2
1 from turtle import* 2 def move(x,y): 3 penup() 4 goto(x,y) 5 pendown() 6 7 def main(): 8 pensize(2) 9 pencolor('blue') 10 11 move(-150,0) 12 circle(50) 13 14 move(0,0) 15 circle(50,steps=4) 16 17 move(150,0) 18 circle(50,steps=5) 19 20 move(300,0) 21 circle(50,steps=6) 22 23 hideturtle() 24 done() 25 26 27 main()
task2
1 from turtle import* 2 def move(x,y): 3 penup() 4 goto(x,y) 5 pendown() 6 7 def main(): 8 setup(800,600) 9 10 radius=20 11 offset=20 12 13 for i in range(9): 14 move(0,-radius) 15 circle(radius) 16 radius+=offset 17 18 hideturtle() 19 done() 20 main()
1 from turtle import* 2 from random import random 3 4 def move(x,y): 5 penup() 6 goto(x,y) 7 pendown() 8 9 def gen_color(): 10 return tuple((random() for i in range(3))) 11 12 def main(): 13 setup(800,600) 14 15 radius=180 16 offset=20 17 18 for i in range(8): 19 move(0,-radius) 20 color(gen_color()) 21 22 begin_fill() 23 circle(radius) 24 end_fill() 25 26 radius-=offset 27 28 hideturtle() 29 done() 30 31 main()
task3
1 from turtle import * 2 def square(size = 50, rgb = 'pink'): 7 pencolor(rgb) 8 for i in range(4): 9 fd(size) 10 left(90) 11 def main(): 12 setup(800, 600) 13 speed(0) 14 n = 3 15 for i in range(n): 16 square(80) 17 left(360/n) 18 hideturtle() 19 done() 20 main()
1 from turtle import * 2 def square(size = 50, rgb = 'pink'): 3 '''绘制正方形 4 :para: size:int 指定边长 (如未指定参数,使用默认值) 5 :para: c: str 指定画笔颜色值 (如未指定参数,使用默认值) 6 ''' 7 pencolor(rgb) 8 for i in range(4): 9 fd(size) 10 left(90) 11 def main(): 12 setup(800, 600) 13 speed(0) 14 n = 10 15 for i in range(n): 16 square(80) 17 left(360/n) 18 hideturtle() 19 done() 20 main()
1 from turtle import * 2 setup(800, 600) 3 pencolor('pink') 4 n = 10 5 for i in range(10): 6 7 for j in range(2): 8 circle(80, 90) 9 left(90) 10 right(360/n) 11 hideturtle() 12 done()
task4
1 from turtle import * 2 setup(800, 600) 3 bgcolor('black') 4 pencolor('white') 5 speed(0) 6 angle = 0 7 size = 2 8 n = 5 # 螺旋n边形 9 count = 50# 循环次数 10 for i in range(count): 11 fd(size) 12 angle += 360/n 13 seth(angle) 14 size += 5 15 hideturtle() 16 done()
task5
1 from turtle import * 2 def move(x,y): 3 penup() 4 goto(x,y) 5 pendown() 6 7 def main(): 8 move(100,100) 9 right(90) 10 begin_fill() 11 for i in range(4): 12 fd(200) 13 right(90) 14 end_fill() 15 16 move(0,-100) 17 left(90) 18 pencolor('red') 19 20 begin_fill() 21 fillcolor('red') 22 circle(100,steps=4) 23 end_fill() 24 hideturtle() 25 done() 26 main()
1 from turtle import * 2 pencolor('blue') 3 pensize(2) 4 n=40 5 for i in range(5): 6 fd(n) 7 left(90) 8 circle(n,90) 9 left(90) 10 fd(n) 11 left(90) 12 n+=20 13 hideturtle() 14 done()
task6
1 from turtle import * 2 from random import random 3 4 setup(800,600) 5 def gen_color(): 6 return tuple((random() for i in range(3))) 7 def rectangle(): 8 color(gen_color()) 9 begin_fill() 10 for i in range(2): 11 forward(5) 12 left(90) 13 forward(20) 14 left(90) 15 end_fill() 16 penup() 17 goto(-10*5,0) 18 pendown() 19 for k in range(20): 20 rectangle() 21 forward(5) 22 23 hideturtle() 24 done()
task7
1 from matplotlib import pyplot as plt 2 def func(x): 3 return 4*x*(1-x) 4 def gen_lst(x,n): 5 ans=[] 6 for i in range(n): 7 t=func(x) 8 ans.append(t) 9 x=t 10 return ans 11 def main(): 12 n=30 13 lst1=gen_lst(0.2,n) 14 lst2=gen_lst(0.2000001,n) 15 x=list(range(1,31)) 16 plt.plot(x,lst1,'ro-',x,lst2,'bs-') 17 plt.xticks(list(range(1,31,4))) 18 plt.legend(['x=0.2','x=0.2000001']) 19 plt.show() 20 main()
task8
1 import jieba 2 from wordcloud import WordCloud 3 from matplotlib import pyplot as plt 4 5 text='''requests是一个常用的HTTP请求库,可以方便地向网站发送HTTP请求,并获取响应结果。 6 Scrapy是一个开源和协作框架,用于从网站中提取数据,是最流行的爬虫框架。 7 SciPy是一个开源的Python算法库和数字工具包,它基于Numpy,用于数学、科学、工程学等领域''' 8 9 word=jieba.lcut(text) 10 t=' '.join(word) 11 t_wc=WordCloud(font_path='msyh.ttc').generate(t) 12 t_wc.to_file('wordcloud.png') 13 plt.imshow(t_wc) 14 plt.axis('off') 15 plt.show()
标签:10,move,range,实验,import,main,def From: https://www.cnblogs.com/-bug/p/17464543.html