Commit a05ab4fc by BellCodeEditor

auto save

parent 5ec53ebb
Showing with 29 additions and 0 deletions
with open(r"c:\Users\EDY\Documents\lesson13-1\sales_list.txt",
"r",encoding="utf-8") as file:
a = file.readlines() # 按行读取,返回列表,一行一数据
final_sum = []
for i in a: # 遍历得到数据
data = i.split() # 分割符,返回列表
sum = 0
for sales in data[1:]:
sum += int(sales)
result = data[0]+ str(sum)+"\n"
final_sum.append(result)
with open(r"c:\Users\EDY\Documents\lesson13-1\new_sales_list.txt","w",encoding="utf-8") as file:
file.writelines(final_sum)
\ 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