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()

Comments

Popular posts from this blog

Python program to calculate age and year when user will be 100 years old

Python program to print numbers less than 5 from the list.