Python Program to print sum of all values in Dictionary

 Python Program to print sum of all values in Dictionary


dict1={1:10,2:20,3:30,4:40,5:50,6:60,7:13,8:"Hello"}
sum=0
for value in dict1.values():
    if isinstance(value,int):
        sum=sum+value
print("The sum of all dictionary values is:",sum)

Output:
The sum of all dictionary values is: 223



Python Program to print sum of all even values in Dictionary

dict1={1:10,2:20,3:30,4:40,5:50,6:60,7:13,8:"Hello"}
sum=0
for value in dict1.values():
    if isinstance(value,int):
        if value%2==0:
            sum=sum+value
print("The sum of all even values in dictionary is:",sum)

Output:
The sum of all even values in dictionary is: 210

टिप्पणी पोस्ट करा

0 टिप्पण्या