From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chap5PracFantasyInv.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Chap5PracFantasyInv.py (limited to 'Chap5PracFantasyInv.py') 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) -- cgit