inv = {'rope': 1,
'劍': 1,
'gold coin': 42,
'dagger': 1,
'arrow': 1} # 倉庫
dragonLoot = ['超級劍',
'gold coin',
'arrow']
def addInventory(inventory, addItems):
inv_dict = {}
inv_dict.update(inventory)
for item in addItems:
if item in inv_dict:
inv_dict[item] += 1
else:
inv_dict[item] = 1
return inv_dict
def diplayInventory(inventory):
print("Inventory:")
for k, v in inventory.items():
print(f"{v} {k}")
print("items number:", len(inventory), "\n")
diplayInventory(inv)
new_inv = addInventory(inv, dragonLoot)
diplayInventory(inv)
diplayInventory(new_inv)