Commit a77eefa8 by BellCodeEditor

auto save

parent 5ec53ebb
Showing with 32 additions and 0 deletions
alist = []
with open("sales_list.txt","r",encoding='utf-8') as f:
#文件对象.readlines() 多行读取 将文件中的数据以列表形式读取进来
r = f.readlines()
#遍历读取进来的列表
for i in r:
#字符串.split("符号") 功能:将字符串按括号里指定的符号进行划分,省略括号内的符号,默认为空格
date = i.split()
#统计义卖款
sum = 0
for sale in date[1:]:
sum += int(sale) # sum = sum + int(sale)
name = date[0] + " " + str(sum) + "\n"
alist.append(name)
with open("sales_list1.txt","a",encoding='utf-8') as f:
#文件对象.writelines(列表)
f.writelines(alist)
\ No newline at end of file
悟空 348
诺依 380
小贝 182
李丽 201
宋扬 107
王明 245
李强 164
孙小白 222
苏琪 137
刘若若 147
刘阳 226
王胜男 123
王娇 131
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