import random as r
color = ['red','orange','blue','green','purple']
r.seed(1)
for i in range(5):
rad = r.
x0 = r.
y0 = r.randint(-100,100)
t.color(r.choice(color))
t.penup()
t.
t.pendown()
t. (rad)
t.done()
import turtle as t
import random as r
color = ['red','orange','blue','green','purple']
r.seed(1)
for i in range(5):
rad = r.randint(20,50)
x0 = r.randint(-100,100)
y0 = r.randint(-100,100)
t.color(r.choice(color))
t.penup()
t.goto(x0,y0)
t.pendown()
t.circle(rad)
t.done()
示例如下:
lt1 = [0.69, 0.292, 0.33, 0.131, 0.61, 0.254]
lt2 = [0.1, 0.8, 0.2]
计算lt1列表和lt2列表的向量内积
k = x1y1 + x2y2 + x3*y3
将每次计算的两组对应元素的值、以及对应元素乘积的累计和K的值显示在屏幕上
img = [0.244, 0.832, 0.903, 0.145, 0.26, 0.452]
filter = [0.1, 0.8, 0.1]
res = []
for i in range(len(img)-2):
res.append(k)
for r in res:
print('{:<10.3f}'.format(r),end = '')
img = [0.244, 0.832, 0.903, 0.145, 0.26, 0.452]
filter = [0.1, 0.8, 0.1]
res = []
for i in range(len(img)-2):
k = 0
for j in range(3):
k = k + filter[j]*img[i+j]
print('k={:<10.3f},filter[{}]={:<10.3f},img[{}+{}]={:<10.3f}'.format(k,j,filter[j],i,j,img[i+j]))
res.append(k)
for r in res:
print('{:<10.3f}'.format(r),end = '')
import turtle as t
import random as r
r.seed(1)
t.pensize(2)
t. ('red')
angles = 6
points=[[0,0],[50,40],[70,80],[-40,30]]
for i in range():
x0,y0 = points(i)
t.penup()
t.goto()
t.pendown()
length = r.randint(6,16)
for j in range(angles):
t. (length)
t.(length)
t.right(360/angles)
t.done()
import turtle as t
import random as r
r.seed(1)
t.pensize(2)
t.pencolor('red')
angles = 6
points=[[0,0],[50,40],[70,80],[-40,30]]
for i in range(4):
x0,y0 = points[i]
t.penup()
t.goto(x0,y0)
t.pendown()
length = r.randint(6,16)
for j in range(angles):
t.fd(length)#fd往前走
t.bk(length)#bk往回走
t.right(360/angles)
t.done()
f = open('data202.txt','r')
for line in f:
for d in unis:
print('{:>4}:{:>4}:{:>4}'.format())
解题思路:
先把数据读取出来,
先统计一共出现了多少个国家,去重后
我再统计每个学校所对应的国家
把每个学校的国家和总的国家进行匹配,然后统计出每个国家对应的学校及数量
最后把结果放在一个大的列表里,进行输出
f = open('data202.txt','r')
school = []
country = []
for line in f:
lines = line.strip('\n').split(",")#lines=['1','麻省理工学院','美国']
if lines != ['']:
country.append(lines[-1])
school.append(lines[1:3])#school=[['麻省理工学院’,‘美国'],[]]
country = list(set(country))
unis=[]
for i in country:
n =0 #计算一个国家里有多少个学校
schools = []#存放同一个国家里的学校名称
result = []#存放一个国家的信息,包括国家名,学校个数,学校名字
for k in school:
if k[1] == i:
schools.append(k[0])
n+=1
#遍历结束得到的结果为 i这个国家 有多少个学校,每个学校的名字信息
result = [i,n,schools]
unis.append(result)
for d in unis:
print('{:>4}:{:>4}:{}'.format(d[0],d[1],''.join(d[2])))
f.close()
import turtle as t
import random as r
r.seed(1)
t.pensize(2)
for i in range(3):
length = r.(20,80)
x0 = r.randint(-100,100)
y0 = r.randint(-100,100)
t.penup()
t.goto()
t.
for j in range(4):
t.fd(length)
t.bd(90*(j+1))
t.done()
import turtle as t
import random as r
r.seed(1)
t.pensize(2)
for i in range(3):
length = r.randint(20,80)
x0 = r.randint(-100,100)
y0 = r.randint(-100,100)
t.penup()
t.goto(x0,y0)
t.pendown()
for j in range(4):
t.fd(length)
t.seth(90*(j+1))
t.done()
sumtime = 0
percls = 0
ts = {}
with open('out.txt','r') as f:
for line in f.readlines
line = line.strip('\n').split(',')#line = ['starting','0.000037','2.102']
sumtime += eval(line[1])
ts[line[0]] = line[2]
print('the total excute time is',sumtime)
tns = list(ts.item())
tns.sort(key=lambda x: x[1],reserve=True)
for i in range(3):
print('the top {} percentage time is {},spent in "{}" operation'.format(i,tns[i][1],tns[i][0]))
import turtle as t
color = ['red','green','blue']
rs = [10,30,60]
for i in range(3):
t.penup()
t.goto(0,-rs[i])
t.pendown()
t.pencolor(color[i])
t.circle(rs[i])
t.done()
import jieba
s = input("请输入一段中文文本,句子之间以逗号或句号分隔:")
for i in slist:
if i in ",。":
continue
print("\n中文词语数是:{}\n".format(m))
import jieba
s = input("请输入一段中文文本,句子之间以逗号或句号分隔:")
slist = jieba.lcut(s)
for i in slist:
if i in ",。":
continue
print(i,end='/')
m += 1
print("\n中文词语数是:{}\n".format(m))
s = ''
for i in slist:
if i in ",。":
print('{.^20}'.format(s))
s+=i
import turtle
n =
for j in range(n):
turtle.
for i in range(4):
turtle.right()
turtle.penup()
turtle.fd()
turtle.done()
import turtle
n = 4
for j in range(n):
turtle.pendown()
for i in range(4):
turtle.fd(40)
turtle.right(90)
turtle.penup()
turtle.fd(80)
turtle.done()
import random as r
r.seed(0)
persons = ['Aele','Bob','lala','baicai']
flag = 3
while flag>0:
flag -= 1
name = input("请输入一个名字:")
if name in persons:
num = r.randint(1000,9999)
print('{} {}'.format(name,num))
elif name == 'q':
break
elif name not in persons:
print('对不起,您输入的名字不存在。')
import turtle as t
import random as r
color = ['red','green','blue','purple','black']
r.seed(1)
for j in range():
t.pencolor(color[r.])
t.penup()
t.goto()
t.()
t.circle()
t.done()
import turtle as t
import random as r
color = ['red','green','blue','purple','black']
r.seed(1)
for j in range(5):
t.pencolor(color[r.randint(0,4)])
t.penup()
t.goto(r.randint(-100,100),r.randint(-100,100))
t.pendown()
t.circle(r.randint(10,30))
t.done()
import jieba
s = input("请输入一个中文字符串,包含逗号和句号:")
k=jieba.lcut(s)
dl = {}
for i in k:
f.close()
import jieba
s = input("请输入一个中文字符串,包含逗号和句号:")
k = jieba.lcut(s)
dl = {}
for i in k:
if len(i)>=2:
dl[i] = dl.get(i,0) + 1
ls = list(dl.item())
for i in range(len(ls)):
f.write('{}:{}'.format(ls[i][0]),ls[i][1])
f.write('\n')
f.close()
import turtle as t
color = ['red','blue','purple','black']
r.seed(1)
for j in range(4):
t.pencolor(color[])
t.penup()
t.goto(r.randint(-100,100),)
t.pendown()
ra = r.randint(50,200)
for i in range():
t.fd()
t.seth(90*i)
t.done()
import turtle as t
import random as r
color = ['red','blue','purple','black']
r.seed(1)
for j in range(4):
t.pencolor(color[r.randint(0,3)])
t.penup()
t.goto(r.randint(-100,100),r.randint(-100,100))
t.pendown()
ra = r.randint(50,200)
for i in range(1,5):
t.fd(ra)
t.seth(90*i)
t.done()
import jieba
dela = '-;;,.()"<>'
s = input("请输入一句话")
print("\n这句话是:{}".format())
....
print("替换之后是:{}".format())
print("里面有{}个词语。".format())
import jieba
dela = '-;;,.()"<>'
s = input("请输入一句话")
print("\n这句话是:{}".format())
new = ""
for i in s:
if i in dela:
i = ""
new += i
wordlists = jieba.lcut(new)
print("替换之后是:{}".format())
print("里面有{}个词语。".format())
祝大家都顺利通过二级呀!