-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfantasy_game_inventory.py
More file actions
39 lines (29 loc) · 1.06 KB
/
fantasy_game_inventory.py
File metadata and controls
39 lines (29 loc) · 1.06 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
# Fantasy Game Inventory : Project Chapter 5
inventory_stuff = {'arrow': 12, 'gold coin': 42, 'rope': 1, 'torch': 6, 'dagger': 1}
def displayInventory(stuff):
'''
To display the inventory items.
'''
print('Inventory:')
item_total = 0
for k, v in stuff.items():
print(str(v) + ' ' + k)
item_total += v
print('Total number of items: ' + str(item_total))
displayInventory(inventory_stuff)
def addToInventory(inventory, addedItems):
'''
to add the looted items(list) in the dictionary
'''
for i in addedItems:
inventory.setdefault(i, 0)
inventory[i] += 1
displayInventory(inventory_stuff)
return inventory
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby', 'platinum']
# def addToDict(inventory, lst): # The best solution "Sometimes the solution is easy but make it complex"
# for i in lst:
# inventory.setdefault(i, 0)
# inventory[i] += 1
# return inventory
print(addToInventory(inventory_stuff, dragonLoot))