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 टिप्पण्या
कृपया तुमच्या प्रियजनांना लेख शेअर करा आणि तुमचा अभिप्राय जरूर नोंदवा. 🙏 🙏