首页 > 其他 > 详细

将文件中各个学生的成绩加总并写入

时间:2019-02-23 14:06:36      阅读:179      评论:0      收藏:0      [点我收藏+]
list1 = ["罗恩 23 35 44", \
"哈利 60 77 68 88 90", \
"赫敏 97 99 89 91 95 90", \
"马尔福 100 85 90"]

with open("xxx", "w", encoding="utf-8") as xxx:
for i in list1:
xxx.writelines(i + "\n")

with open("xxx", "r", encoding="utf-8") as xxx:
list2 = xxx.readlines()

for i in list2:
data = i.split()
s = 0
for j in data[1:]:
s = s + int(j)
res = data[0] + ":"+str(s)
with open("xxx", "a", encoding="utf-8") as xxx:
xxx.writelines(res + "\n")
print(res)

将文件中各个学生的成绩加总并写入

原文:https://www.cnblogs.com/baqycl/p/10422447.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!