# 实验五

2022-05-14 16:32:49  阅读：6  来源： 互联网

```with open('data3.txt','r',encoding='utf-8') as f:
f.close()
with open('data3_proxessed.txt','w',encoding='utf-8') as b:
a=['四舍五入后数据']
for i in range(len(data)):
data[i]=data[i].strip('\n')
for i in data[1:]:
a.append(str(round(eval(i))))
for i in range(len(data)):
b.write(data[i]+'\t'+a[i]+'\n')
b.close()
ys=[]
zz=[]
for i in data[1:]:
i=eval(i.strip('\n'))
ys.append(i)
print(f'原始数据:\n',ys)
for i in data[1:]:
i=round(eval(i))
zz.append(i)
print('四舍五入后数据:\n',zz)```

```with open('data4.txt','r',encoding='utf-8') as f:
a=data.split('\n')
m=a.pop(0)
x=[]
for i in a:
a=i.split('\t')
x.append(a)
y=sorted(x,key=lambda x:(x[2],x[3]),reverse=True)
with open('data4_processed.txt','w',encoding='utf-8') as g:
g.write(m+'\n')
print(m)
for n in y:
g.write('\t'.join(n))
g.write('\n')
print('\t'.join(n))```

```with open('data5.txt','r',encoding='utf-8') as f:
a=data.split('\n')
b='\n'.join(a)
blank_counts=0
with open('data5_with_line.txt','w',encoding='utf-8') as g:
for i in range(len(a)):
for x in a[i]:
if x==' ':
blank_counts+=1
else:
blank_counts=blank_counts
g.write(f'{i+1} {a[i]}\n')
print(f'''行数：{len(a)}