# 实验五

 1 with open('data3.txt','r+',encoding='utf-8')as f:
2     a=[]
3     for i in f:
4         i=i.strip('\n')
5         a.append(i)
6 a.pop(0)
7 b=[eval(i) for i in a]
8 print(f'原始数据:\n{b}')
9 c=[round(eval(i)) for i in a]
10 print(f'四舍五入后数据:\n{c}')
11 with open('data3-1.txt','w',encoding='utf-8')as f:
12     w1=['原始数据']+[str(i) for i in a]
13     w2=['四舍五入后的数据']+[str(i) for i in c]
14     for i in range(len(a)):
15         f.write(f'{w1[i]}\t{w2[i]}\n')

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

 1 with open('data5.txt', 'r', encoding='UTF-8') as f:
2     text = ''.join([i for i in f])
3     print(f'行数：{len(text.splitlines())}')
4     print(f'单词数：{len(text.split())}')
5     print(f"空格数：{text.count(' ')}")
6     print(f'字符数：{len(text)}')
7
8 with open('data5.txt', 'r', encoding='UTF-8') as f:
14     f.write(new_content)