直接上代码:

url = "D://zhangdan.txt"
arr = []
sum = 0
with open(url) as f:
for i in f:
arr.append(float(i))

for i in range(len(arr)):
print(f'{i+1}号 : {arr[i]}元')
sum = sum + arr[i]
print(f'该月份工资为{sum}元')

 

-----------------------------------------------------------------------------------------------------------------------------------------