从in.txt文件读数据,对于该文件每一行:
求该行中各个数(可能是整数,也可能是浮点数)的最大、最小值,
把最大值和最小值写入文件out.txt,写成一行,最大值在前,两个数之间隔两个空格。
30 30 0 30 20 10 395 92
35 35 0 50 20 20 430 100
35 35 0 50 20 20 430 100
35 35 1.2 50 20 20 365 85
32.5 32.5 0 47.5 20 0 381.33333 89
【样例输出】
395 0
430 0
430 0
365 1.2
381.33333 0
以上评论错的
with open(file=r'../in.txt', mode='r') as f:
for lines in range(len(open(file=r'../in.txt', mode='r').readlines())):
zf_list = f.readline().replace('\n', '')
if zf_list:
sz_list = []
for i in zf_list.split(" "):
# print(type(i),end=" ")
sz = eval(i)
sz_list.append(sz)
sorted_list = sorted(sz_list, reverse=True)
print(str(sorted_list[0])+" "+str(sorted_list[len(sz_list)-1]))