diff options
author | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
---|---|---|
committer | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
commit | 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch) | |
tree | 84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chap5PracFantasyInv.py |
Diffstat (limited to 'Chap5PracFantasyInv.py')
-rw-r--r-- | Chap5PracFantasyInv.py | 28 |
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) |