#!/env/bin/python file = '/Users/{user}/code/test/lie_qiuhe.txt' with open(file,'r',encoding='utf-8') as f: list = [] for i in f: tmp = i.split(',') # print(float(tmp[1])) f1_tmp = float(tmp[0]) f2_tmp = float(tmp[-1]) # f1_tmp = int(tmp[1]) # f2_tmp = int(tmp[-1]) f_tmp = f1_tmp * f2_tmp # print(tmp[1],tmp[-1]) # print(f_tmp) list.append(f_tmp) print(list) sum = 0 for i in list: sum += i print(sum)
The contents of the document
1,1,1,1,1
0.3,0.5,0.3,0.5,1
1,1,3,3,1
1,1,1,1,1
1,1,1,1,1
1,3,3,6,2
1,5,1,5,1
1,1,1,1,1
1,1,1,1,1
2,5,5,10,1
1,1,1,1,1
3,3,4,10,3
1,1,1,1,1
1,1,2,20,1
0.5,1,5,30,1
1,1,1,1,1