Commit 9d1a6b29 by BellCodeEditor

auto save

parent 91583b8c
Showing with 10 additions and 4 deletions
list=[]
with open(r'C:\Users\yd\Documents\lesson13-1\sales_list.txt','r',encoding='utf-8') as f1:
data = f1.readlines() #返回数据列表
for i in data: #对数据列表进行遍历
new_data = i.split() #对列表中的元素(字符串)进行分割,并且生成一个列表
print(new_data[1:]) #打印该列表除第一项以外的其他项
#print(new_data[1:]) #打印该列表除第一项以外的其他项
sum = 0
for j in new_data[1:]:
sum = sum+int(j)
list.append(new_data[0]+str(sum))
with open(r'C:\Users\yd\Documents\lesson13-1\sales_list.txt','a',encoding='utf-8') as f2:
f2.writelines(list)
......@@ -10,4 +10,4 @@
刘若若 11 11 13 11 20 15 13 29 24
刘阳 11 15 22 11 23 26 22 15 17 52 12
王胜男 27 15 15 26 13 12 15
王娇 12 11 12 12 15 35 23 11
\ No newline at end of file
王娇 12 11 12 12 15 35 23 11悟空348诺依380小贝182李丽201宋扬107王明245李强164孙小白222苏琪137刘若若147刘阳226王胜男123王娇131
\ 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