Python Program to sum all the items(values) in a dictionary.
#Python Program to sum all the items(values) in a dictionary.
dict1={}
list0=[]
list1=[]
def createDict():
for i in range(N):
key=input("Enter key for item %d:"% i)
list0.append(key)
print("\nNote: Please enter values for key in degits to get sum.")
for i in range(N):
value=int(input("Enter value for key "+list0[i]+":"))
list1.append(value)
for i in range(N):
dict1[list0[i]]=list1[i]
print("\nEntered dictionary is:")
print(dict1)
def sumval():
print("\nSum of values entered in dictionary is:")
print(sum(dict1.values()))
N = int(input("\nEnter number of items to enter in dictionary:"))
createDict()
sumval()
dict1={}
list0=[]
list1=[]
def createDict():
for i in range(N):
key=input("Enter key for item %d:"% i)
list0.append(key)
print("\nNote: Please enter values for key in degits to get sum.")
for i in range(N):
value=int(input("Enter value for key "+list0[i]+":"))
list1.append(value)
for i in range(N):
dict1[list0[i]]=list1[i]
print("\nEntered dictionary is:")
print(dict1)
def sumval():
print("\nSum of values entered in dictionary is:")
print(sum(dict1.values()))
N = int(input("\nEnter number of items to enter in dictionary:"))
createDict()
sumval()
Comments
Post a Comment