Python Program to Multiply All the Items in a Dictionary

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

Problem Description

The program takes a dictionary and multiplies all the items in the dictionary.

Problem Solution

1. Declare and initialize a dictionary to have some key-value pairs.
2. Initialize a variable that should contain the total multiplied value to 1.
3. Use the for loop to traverse through the values of the dictionary.
4. Then multiply all the values in the dictionary against each other.
5. Print the total multiplied value.
6. Exit.

Program/Source Code

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

d={'A':10,'B':10,'C':239}
tot=1
for i in d:    
    tot=tot*d[i]
print(tot)
Program Explanation

1. A dictionary is declared and initialized to have some key-value pairs.
2. The total variable is initialized to 1.
3. The for loop is used to traverse through the values of the dictionary.
4. Then all the values in the dictionary are multiplied against each other.
5. The total multiplied value is printed.

advertisement
advertisement
Runtime Test Cases
 
Case 1:
23900

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.