# 实验五

 1 with open ('data3.txt','r',encoding='utf-8')as f:
3     del a[0]
4     b=[]
5     c=[]
6     for i in a:
7         if float(i.replace('\n',''))-int(float(i.replace('\n','')))>=0.5:
8             b.append(int(float(i.replace('\n','')))+1)
9         else:
10             b.append(int(float(i.replace('\n',''))))
11         c.append(float(i.replace('\n','')))
12     print('or data:')
13     print(c)
14     print('new data')
15     print(b)
16     c.insert(0,'or')
17     b.insert(0,'ne')
18 with open ('data3p.txt','w',encoding='utf-8')as f:
19     for i in c:
20         f.write(str(i)+'\t'+str(b[c.index(i)])+'\t'+'\n')

 1 with open ('data4.txt','r',encoding='utf-8')as f:
3     v=[]
4     z=[]
5     m=[]
6     n=[]
7     o=[]
8     p=[]
9     u=[]
10     x=[]
11     for i in a :
12        v.append(i.split('\t'))
13     o.append(v[0])
14     for i in v:
15
16         if i[2]=='Acting':
17             z.append(i)
18         elif i[2]=='Music':
19             m.append(i)
20     for i in z:
21         n.append(int(i[3].replace('\n','')))
22 t=[]
23 for i in n:
24     t.append(i)
25 for i in z:
26     o.append(z[t.index(max(n))])
27     n.remove(max(n))
28 for i in m:
29     p.append(int(i[3].replace('\n','')))
30 for i in p:
31     u.append(i)
32 for i in m:
33     x.append(m[u.index(max(p))])
34     p.remove(max(p))
35 for i in x:
36     o.append(i)
37 with open ('data4p.txt','w',encoding='utf-8')as f:
38     for i in o:
39         f.write(i[0]+'\t'+i[1]+'\t'+i[2]+'\t'+i[3])
40         print(i[0]+'\t'+i[1]+'\t'+i[2]+'\t'+i[3])

 1 with open ('data5.txt','r',encoding='utf-8')as f:
3
4     b=[]
5     c=[]
6     z=0
7     for i in a :
8         for j in i.split(' '):
9             b.append(j)
10         for j in i:
11             c.append(j)
12     print('lines:',len(a))
13     print('words:',len(b)-1)
14
15     for i in b:
16         if i.find('\n')==-1:
17             z+=1
18
19     print('space:',str(z-1))
20     print('str:',str(len(c)))
21 with open ('data5p.txt','w',encoding='utf-8')as f:
22     for i in a:
23         f.write(str(a.index(i)+1)+'    '+i)

posted @ 2022-05-17 12:37  pray4hell  阅读(6)  评论(3编辑  收藏  举报