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)

猜你喜欢

转载自blog.csdn.net/Katherine_pbq/article/details/86476058