首页 > 其他分享 >实验六

实验六

时间:2023-06-13 12:45:23浏览次数:26  
标签:10 move range 实验 import main def

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

相关文章

  • 实验7 面向对象编程与内置模块
    实验任务1#task1源码1'''2银行账号3数据:持卡人姓名、账号、当前余额4操作:取款、存款、打印账户信息、返回账户余额5'''67classAccount:#一个模拟银行账户的简单类89def__init__(self,name,account_number,initial_amount=10):#构......
  • 实验七
    任务1classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,amount):self._balance+=amount......
  • 实验7
    任务1classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,amount):self._balance+=amount......
  • 实验7
    task4编程代码#include<stdio.h>#include<stdlib.h>intmain(){FILE*fp;intx=0;charch;if((fp=fopen("d:\\data4.txt","r"))==NULL){printf("Failtoinitialize\n");e......
  • 实验七
    TASK4#include<stdio.h>intmain(){charch;intcount=0;FILE*fp;fp=fopen("D:\data4.txt","r");if(fp==NULL){printf("failtoopenfile\n");......
  • 实验7
    task1.py1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._ca......
  • 实验7
    task1_1#include<stdio.h>#defineN7#defineM80typedefstruct{charname[M];charauthor[M];}Book;intmain(){Bookx[N]={{"《雕塑家》","斯科特·麦克劳德"},{"《灯塔》","克里斯多夫·夏布特"},......
  • 实验7
    实验任务1实验源码1classAccount:2def__init__(self,name,account_number,initial_amount=10):3self._name=name4self._card_no=account_number5self._balance=initial_amount6defdeposit(self,amount):7......
  • 实验7 面向对象编程与内置模块
    task1程序源码:1'''2银行账户3数据:持卡人姓名、账号、当前余额4操作:取款、存款、打印账户信息、返回账户余额5'''6classAccount:7'''一个模拟银行账户的简单类'''89def__init__(self,name,account_number,initial_amount=1......
  • 实验7 面向对象编程与内置模块
    task1实验源码:1#12classAccount:3def__init__(self,name,account_number,initial_amount=10):4self._name=name5self._card_no=account_number6self._balance=initial_amount78defdeposit(self,amount):9......