Skip to content

Commit 7b35a9a

Browse files
committed
Added solutions for Fantasy Game Inventory
1 parent 7b72b55 commit 7b35a9a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Fantasy_Game_Inventory/main.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Fantasy Game Inventory
2+
3+
#Part 1
4+
5+
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
6+
7+
def displayInventory(inventory):
8+
print("Inventory:")
9+
item_total = 0
10+
for k, v in inventory.items():
11+
print(str(v)+" " + k)
12+
item_total += v
13+
print("Total number of items: " + str(item_total))
14+
15+
displayInventory(stuff)
16+
17+
#Part 2
18+
19+
def addToInventory(inventory, addedItems):
20+
for item in addedItems:
21+
if item in inventory.keys():
22+
inventory[item] += 1
23+
else:
24+
inventory[item] = 1
25+
return inventory
26+
inv = {'gold coin': 42, 'rope': 1}
27+
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
28+
inv = addToInventory(inv, dragonLoot)
29+
displayInventory(inv)

0 commit comments

Comments
 (0)