Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 8, 2016 20:07
Show Gist options
  • Save Gwith/e8a984a4491e952350d9c1aa7f670431 to your computer and use it in GitHub Desktop.
Save Gwith/e8a984a4491e952350d9c1aa7f670431 to your computer and use it in GitHub Desktop.
import math
def displayInventory(inventory):
print('Inventory')
for k, v in inventory.items():
print(v, k)
print('Total number of items:' + ' ' + str(sum(inventory.values())))
def addToInventory(inventory, addedItems):
for i in range(len(addedItems)):
inventory[i] = inventory.get(i, 0) + 1
return inventory
inv = {'gold coin':42, 'rope':1}
dragonLoot = ['gold coin','dagger','gold coin','gold coin','ruby']
inv = addToInventory(inv, dragonLoot)
displayInventory(inv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment