In this python dictionary program, we will find the product of all items in the dictionary.
Steps to solve the program
- Take a dictionary as input and create a variable and assign its value equal to 1.
- Use for loop to iterate over values in the dictionary using values().
- During iteration multiply the value by the variable that we have created.
- Print the output.
dict1 = {'a':2,'b':4,'c':5}
result = 1
for val in dict1.values():
result *= val
print(result)
Output :
40