-8
students={
1: {"pup1": "001", "s1": 10, "s2": 20},

2: {"pup2": "124", "s1": 20, "s2": 30},

3: {"pup3": "125", "s1": 30, "s2": 40}}
  1. List item
Nihal
  • 5,262
  • 7
  • 23
  • 41

1 Answers1

-2

If you want to add all the values of s1, you need to iterate over the values() of dictionary students.

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)
xxx
  • 1,153
  • 1
  • 11
  • 23
eiram_mahera
  • 950
  • 9
  • 25