inv = {'rope': 1,
'劍': 1,
'gold coin': 42,
'dagger': 1,
'arrow': 1} # 倉庫
dragonLoot = ['超級劍',
'gold coin',
'arrow']
def addInventory(inventory, addItems):
for item in addItems:
if item in inventory:
inventory[item] += 1
else:
inventory[item] = 1
return inventory
def diplayInventory(inventory):
# 顯示字典用的函數
print("Inventory:")
for k, v in inventory.items():
print(f"{v} {k}")
print("items number:", len(inventory))
addInventory(inv, dragonLoot)
diplayInventory(inv)