I am new on python. I want to add a function named delFromInventory(inventory, deletedItems), whereby the deletedItems parameter is the input from the user if he/she want to remove any items from the inventory. This function should be callback before displayInventory(). May i know how and where should i write the script?
Below is my current code.
def displayInventory(inventory):
print('Inventory:')
item_total = 0
for k, v in inventory.items():
print(str(v) + ' ' + k)
item_total += v
print('Total Items: ' + str(item_total))
def addToInventory(inventory, added_items):
for loot in addedItems:
if loot not in inv:
inv[loot] = 1
else:
inv[loot] += 1
inv = {'gold coin': 42, 'rope': 1}
addedItems = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
addToInventory(inv, addedItems)
displayInventory(inv)