students={1: {"pup1": "001", "s1": 10, "s2": 20},2: {"pup2": "124", "s1": 20, "s2": 30},3: {"pup3": "125", "s1": 30, "s2": 40}}项目清单
1 回答
慕丝7291255
TA贡献1859条经验 获得超6个赞
如果要将s1的所有值相加,需要遍历字典student的values()
students={
1: {"pup1": "001", "s1": 10, "s2": 20},
2: {"pup2": "124", "s1": 20, "s2": 30},
3: {"pup3": "125", "s1": 30, "s2": 40}}
sum1 = 0
for data in students.values():
sum1 += data['s1']
avg = sum1 / len(students)
print(sum1)
print(avg)
添加回答
举报
0/150
提交
取消