Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 9, 2016 02:52
Show Gist options
  • Select an option

  • Save Gwith/fbaa4291895cb72a5497268375bfe233 to your computer and use it in GitHub Desktop.

Select an option

Save Gwith/fbaa4291895cb72a5497268375bfe233 to your computer and use it in GitHub Desktop.
import pprint
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
def displayInventory(inventory):
print("Inventory:")
item_total = 0
for k, v in inventory.items():
print(v, k)
item_total += v
print("Total number of items: " + str(item_total))
displayInventory(stuff)
def addToInventory(inventory, addedItems):
for item in addedItems:
inventory[item] += item
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