【发布时间】:2022-10-08 02:31:56
【问题描述】:
我想总结一下 For 循环中的要点。 正如您在我的代码中看到的那样,“点”中的元素(条目)数量是不同的。 有人可以帮我实现这个pytonically吗?
student1 = {'name': 'Hans', 'points': [285, 210, 135, 100, 300]}
student2 = {'name': 'Peter', 'points': [65, 56, 48]}
students = [student1, student2]
for stud in students:
sumpoints = stud['points'][0]+stud['points'][1]+stud['points'][2]
print(sumpoints)]
【问题讨论】:
-
提示:使用
sum函数 -
你能澄清一下吗?
sumpoints是单个学生的总分,还是所有学生的总分?
标签: python