results = []
with open('scores.txt',mode='r+',encoding='gbk') as f1:
lines = f1.readlines()
f1.close()
for line in lines:
data = https://www.it610.com/article/line.split()
print ('学生各科成绩:\n',data)
sum = 0
for i in data[1:]:
sum+=int(i)
result = '%s:%d\n'%(data[0],sum)
print ('总分=',result)
results.append(result)
print (results)
with open ('output.txt',mode='w+',encoding='gbk') as f2:
#write只能向文件写入str
#writelines可以向文件写入list
f2.writelines(results)
f2.close()
#list
list1=['hello','world']
list1.append('beijing')
print('更新后的列表:',list1)