Write a Python Program to Multiply All Items in a Dictionary with a practical example.
In this Python program, we are using a for loop to iterate over each element in this Python Dictionary. Inside the for loop, we are multiplying those values by the total variable.
myDict = {'x': 20, 'y':5, 'z':60}
print("Dictionary: ", myDict)
total = 1
# Multiply Items
for key in myDict:
total = total * myDict[key]
print("\nAfter Multiplying Items in this Dictionary: ", total)

Python Program to Multiply Items in a Dictionary Example 2
This program uses a Python For Loop along with the Python dict.values function to multiply values in a Dictionary.
myDict = {'x': 2, 'y':50, 'z':70}
print("Dictionary: ", myDict)
total = 1
# Multiply Items
for i in myDict.values():
total = total * i
print("\nAfter Multiplying Items in this Dictionary: ", total)
Multiply dictionary items output
Dictionary: {'x': 2, 'y': 50, 'z': 70}
After Multiplying Items in this Dictionary: 7000
Also Read
- Python Program to Remove Given Key from a Dictionary
- Python Program to find the Sum of Items in a Dictionary