summaryrefslogtreecommitdiff
path: root/Chap5PracFantasyInv.py
diff options
context:
space:
mode:
Diffstat (limited to 'Chap5PracFantasyInv.py')
-rw-r--r--Chap5PracFantasyInv.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Chap5PracFantasyInv.py b/Chap5PracFantasyInv.py
new file mode 100644
index 0000000..e8235f3
--- /dev/null
+++ b/Chap5PracFantasyInv.py
@@ -0,0 +1,28 @@
+#!Python
+
+#Chapter 5 Fantasy Game Inventory Practice
+
+inv = {'rope': 1, 'gold coin': 42}
+
+dragonLoot = ['gold coin','dagger','gold coin','gold coin','ruby']
+
+
+def addToInventory(inventory, addItems):
+ for k in range(len(addItems)):
+ if addItems[k] in inventory.keys():
+ inventory[addItems[k]] += 1
+ else:
+ inventory.setdefault(addItems[k], 1)
+ return inventory
+
+
+def displayInventory(inventory):
+ print('Inventory:')
+ item_total = 0
+ for k, v in inventory.items():
+ print(str(v) + ' ' + k)
+ item_total += v
+ print('Total number of items: ' + str(item_total))
+
+inv = addToInventory(inv, dragonLoot)
+displayInventory(inv)