Commit 915f087c by BellCodeEditor

auto save

parent 0bea6157
Showing with 14 additions and 0 deletions
list1 = []
with open(r"D:\python课件\文件读写\sales_list.txt","r",encoding="utf-8") as file:
a = file.readlines()
for i in a: # 遍历每一行的数据
data = i.split() # 每一行分割成单独的个体
sum = 0 # 统计每个人的总额
for sales in data[1:]: # 遍历除名字外的义卖款
sum += int(sales) # 将所有的义卖款相加
new_data = data[0] + str(sum) + "\n"
list1.append(new_data) # 将所有的数据放进列表中
with open(r"D:\python课件\文件读写\new_sales_list.txt","w",encoding="utf-8") as file:
file.writelines(list1) # 只能添加列表
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment