# the addToInventory function takes 2 parameters, an inventory (dictionary) and the addedItems (a list)
def addToInventory(inventory, addedItems):
    # this for-loop iterates through each item in addedItems
    for i in range( len(addedItems) ):
        # if the addedItem indexed by i is a key in the inventory, then increase the count of the value
        if addedItems[i] in inventory.keys():
            inventory[ addedItems[i] ] += 1
        # otherwise, add the item key to the inventory and set its value to 1
        else:
            inventory[ addedItems[i] ] = 1
    #return the inventory to the caller of this function
    return inventory

# this is the code from the previous question
def displayInventory(inventory):
    print("Inventory:")
    item_total = 0
    for k, v in inventory.items():
        print( str(v) + " " + k )
        item_total += v
    print("Total number of items: " + str(item_total))


inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
displayInventory(inv)
inv = addToInventory(inv, dragonLoot)
displayInventory(inv)