# 实验五

 1 with open('data3.txt','r',encoding='utf-8')as f:
3     p=[]
4     for i in t:
5         if t[0]==i:
6             y='原始数据'+'\t'+'四舍五入后数据'+'\n'
7             p.append(y)
8         else:
9             y=i.strip('\n')+'\t'+str(round(eval(i)))+'\n'
10             p.append(y)
11 with open('data_process.txt','w',encoding='utf-8')as f:
12     x=''.join(p)
13     f.write(x)
14 with open('data_process.txt','r',encoding='utf-8')as f:
16     a=[]
17     b=[]
18     for i in t:
19         if t[0]!=i:
20             y=i.strip('\n')
21             z=y.split('\t')
22             a.append(eval(z[0]))
23             b.append(eval(z[1]))
24 print('原始数据:','\n',a)
25 print('四舍五入后数据:','\n',b)

 1 with open('data4.txt', 'r+', encoding='utf-8') as f:
2     str = [j.strip('\n').split('\t') for j in f]
3     a = str.pop(0)
4     str.sort(key=lambda x: (x[2], -int(x[-1])))
5     print('\t'.join(a))
6     for i in str:
7         print('\t'.join(i))
8 with open('data4_progressed.txt', 'w') as f:
9     f.write('\t'.join(a))
10     f.write('\n')
11     for i in str:
12         f.write('\t'.join(i))
13         f.write('\n')

 1 with open('data5.txt','r',encoding='utf-8')as f:
3 l=text1.splitlines()
4 print('行数：'+str(len(l)))
5 print('单词数：'+str(len(text1.split())))
6 print('空格数：'+str(text1.count(' ')))
7 print('字符数：'+str(len(text1)))
8 with open('data5_with_line.txt','w',encoding='utf-8')as f:
9     for i in range(len(l)):
10         f.write(str(i+1)+'  '+l[i]+'\n')

posted @ 2022-05-16 11:32  气工吴旭  阅读(10)  评论(2编辑  收藏  举报