JavaScript
x
7
1
students={
2
1: {"pup1": "001", "s1": 10, "s2": 20},
3
4
2: {"pup2": "124", "s1": 20, "s2": 30},
5
6
3: {"pup3": "125", "s1": 30, "s2": 40}}
7
- List item
Advertisement
Answer
If you want to add all the values of s1, you need to iterate over the values() of dictionary students.
JavaScript
1
16
16
1
students={
2
1: {"pup1": "001", "s1": 10, "s2": 20},
3
4
2: {"pup2": "124", "s1": 20, "s2": 30},
5
6
3: {"pup3": "125", "s1": 30, "s2": 40}}
7
8
sum1 = 0
9
for data in students.values():
10
sum1 += data['s1']
11
12
avg = sum1 / len(students)
13
14
print(sum1)
15
print(avg)
16