Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions fantasy-game-inventory/game-inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ def addToInventory(inventory, addedItems):
Returns:
updatedInventory (dict): Inventory containing updated items and their counts
"""
updatedInventory = dict(inventory)
# your code goes here
# YOUR CODE GOES HERE
newInventory = dict(inventory)
for item in addedItems:
updatedInventory.setdefault(item, 0)
updatedInventory[item] += 1

return updatedInventory
newInventory.setdefault(item, 0)

if item not in inventory.keys():
inventory[item] = 0
newInventory = inventory
for i in newInventory.keys():
if i in addedItems:
newInventory[i] += 1

elif item in inventory.keys():
newInventory[item] += 1
return newInventory



Expand All @@ -47,4 +55,4 @@ def addToInventory(inventory, addedItems):
inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
inv = addToInventory(inv, dragonLoot)
displayInventory(inv)
displayInventory(inv)