Skip to content

Instantly share code, notes, and snippets.

@indeedwatson
Created July 19, 2016 23:24
Show Gist options
  • Save indeedwatson/7ef43097ab134ad615f59cad45195ab3 to your computer and use it in GitHub Desktop.
Save indeedwatson/7ef43097ab134ad615f59cad45195ab3 to your computer and use it in GitHub Desktop.
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ['gold coin', 'dagger', 'gold coin',
'gold coin', 'ruby']
def addToInventory(inventory, addedItems):
for item in addedItems:
if item in inventory:
inventory[item] += 1
else:
inventory[item] = 1
return inventory
def displayInventory(inventory):
print("Inventory:")
item_total = 0
for k, v in inventory.items():
if v != 1:
k += 's'
print(v, k)
item_total += v
print("Total number of items: " + str(item_total))
inv = addToInventory(inv, dragonLoot)
displayInventory(inv)
# displayInventory(stuff)
@rshelat97
Copy link

rshelat97 commented Jun 15, 2018

if you want, you can just use scrap the code for addToInventory and do this:
def addToInventory(inventory, addedItems): print("adding: " + str(addedItems)) inventory.update(addedItems) return inventory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment