Python Program to Find the Sum of All the Items in a Dictionary

This is a Python Program to find the sum all the items in a dictionary.

Problem Description

The program takes a dictionary and prints the sum of all the items in the dictionary.

Problem Solution

1. Declare and initialize a dictionary to have some key-value pairs.
2. Find the sum of all the values in the dictionary.
3. Print the total sum.
4. Exit.

Program/Source Code

Here is source code of the Python Program to find the sum all the items in a dictionary. The program output is also shown below.

d={'A':100,'B':540,'C':239}
print("Total sum of values in the dictionary:")
print(sum(d.values()))
Program Explanation

1. The sum() function is used to find the sum of all the values in the dictionary.
2. The total sum of all the values in the dictionary is printed.
3. Exit.

advertisement
advertisement
Runtime Test Cases
 
Case 1:
Total sum of values in the dictionary:
879

Sanfoundry Global Education & Learning Series – Python Programs.

To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.