Python列表求平均值的流程分析:
● 读取数据使用open('data.txt','r')
● 文件读取完毕后需要关闭f.close()
● 统计分数需通过2次split()分割,返回list
实现的代码方案:
f =open(‘data.txt’,’r’)
for Line in f:List line split(,')
len(List)
for course in List
items course split(":eval(items[1])
print("总和是:{},平均值是:{:.2f}". format(s,S/n)