实验6

task1_1.py

from turtle import *

def moveto(x,y):
penup()
goto(x,y)
pendown()
def main():
setup(800,600)
speed(0)
for radius in range(20,200,20):
moveto(0,-radius)
circle(radius)

hideturtle()
down()

if __name__=='__main__':
main()

 

 task1_2.py

from turtle import *
def moveto(x,y):
penup()
goto(x,y)
pendown()
def main():
setup(800,600)
speed(0)
for radius in range(180,0,-20):
moveto(0,-radius)
circle(radius)

hideturtle()
down()

if __name__=='__main__':
main()

实验任务2:

from turtle import *
from random import random
def moveto(x,y):
penup()
goto(x,y)
pendown()
def main():
setup(800,600)
speed(0)
for radius in range(180,0,-20):
moveto(0,-radius)
rgb=tuple(random() for i in range(3))
color(rgb)
begin_fill()
circle(radius)
end_fill()
hideturtle()
done()
if __name__=='__main__':
main()

 

 task3.py

from turtle import *
def square(size=50,rgb='orange'):
pencolor(rgb)
for i in range(4):
fd(size)
left(90)
def main():
setup(800,600)
speed(0)
for i in range(3):
square(80)
left(120)
hideturtle()
done()

if __name__=='__main__':
main()

 

 变式:

from turtle import *
def square(size=50,rgb='orange'):
pencolor(rgb)
for i in range(4):
fd(size)
left(90)
def main():
setup(800,600)
speed(0)
for i in range(11):
square(80)
left(36)
hideturtle()
done()

if __name__=='__main__':
main()

 

 实验任务4:

 

 

from turtle import *
setup(800,600)
pencolor('pink')
speed(10)
for i in range(4):
for i in range(2):
circle(80,90)#90指画4分之一圆
left(90)
left(90)

done()

 

实验任务5:

from turtle import *
setup(800,600)
pencolor('white')
bgcolor('black')
speed(0)
angle=0
size=2
for i in range(10):
for j in range(4):
fd(size)
angle += 91
seth(angle)
size += 5
hideturtle()
done()

 

 

 变式:

from turtle import *
setup(800,600)
pencolor('white')
bgcolor('black')
speed(0)
angle=0
size=2
for i in range(10):
for j in range(5):
fd(size)
angle += 73
seth(angle)
size += 5
hideturtle()
done()

 

 

实验任务6:

from turtle import *
from random import random
def turn():
fd(20)
left(90)
fd(40)
left(90)
setup(800,600)
def square():
rgb=tuple(random() for i in range(3))
color(rgb)
begin_fill()
for j in range(2):
turn()
end_fill()
penup()
goto(-200,0)
pendown()
for k in range(20):
square()
fd(20)
hideturtle()
done()

 

 

 实验任务7:

 

import matplotlib.pyplot as plt
from random import randint
plt.rcParams['font.sans-serif']=['SimHei']
date=list(range(18,28))
temperature_high=[randint(27,37) for i in range(10)]
temperature_low=[randint(19,22) for i range(10)]
plt.title('未来十天天气预报')
plt.xlim(18,27)
plt.ylim(18,40)
x_ticks=list(range(18,28))
y_ticks=list(range(18,42,2))
plt.xticks(x_ticks)
plt.yticks(y_ticks)
plt.xlabel('日期')
plt.ylabel('温度')
plt.plot(date,temperature_high,marker='o',label='最高温')
plt.plot(date,temperature_low,marker='o',label='最低温')
plt.legend(['最高温','最低温'])
plt.show()

实验7

import jieba
text1 = '南京信息工程大学是一所综合性大学。'
print(jieba.lcut(text1))
print(jieba.lcut(text1,cut_all=True))
print(jieba.lcut_for_search(text1) )

 

import jieba
text2 = '这场学术报告举办的规格高大上。主讲人的报告很前沿,不明觉厉。'
print(jieba.lcut(text2))
jieba.add_word('高大上')
jieba.add_word('不明觉厉')#添加词汇到分词字典
print(jieba.lcut(text2))

 

 

 



posted @ 2021-06-13 12:48  叹之  阅读(73)  评论(1编辑  收藏  举报