Created
July 19, 2016 23:24
-
-
Save indeedwatson/7ef43097ab134ad615f59cad45195ab3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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