1. 程式人生 > >python_dict_好玩遊戲的物品清單

python_dict_好玩遊戲的物品清單

Inventory
列出清單並計算總和

stuff = {'rope':1,'torch':6,'gold coin':42,'dagger':1,'arrow':12}
def displayInventory(stuff):
    print('Inventory:')
    value_total = 0 
    for k,v in stuff.items():
        print(str(v) + '   ' + k)
        value_total += v
    print('Total number od items:' + str(value_total)
) displayInventory(stuff)