-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory.py
More file actions
27 lines (23 loc) · 828 Bytes
/
inventory.py
File metadata and controls
27 lines (23 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# inventory.py
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(str(inventory.get(k, 0)) + " " + k)
item_total += v
print("Total number of items: " + str(item_total))
#displayInventory(stuff)
def addToInventory(inventory, addedItems):
# your code goes here
for i in range(len(addedItems)):
if i in inventory:
inventory[addedItems[i]] += 1
else:
inventory.setdefault(addedItems[i], 0)
inventory[addedItems[i]] += 1
return inventory
inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
inv = addToInventory(inv, dragonLoot)
displayInventory(inv)