python程序-->字典物品统计算法
2017-03-23 15:08
190 查看
写一函数为displayInventory(),它可接受任何可能的物品清单,并能把其中的内容梳理出来
stuff = {'saber':1,'caster':2,'lancer':10,'accseeion':3}
def displayInventory(inventory):
item_total = 0
for k , v in inventory.items():
print(str(v)+' '+ k)
item_total += v
print('The number of items :' + str(item_total))
displayInventory(stuff)
对于列表stuff = {'saber':1,'caster':2,'lancer':10,'accseeion':3}
结果如下
stuff = {'saber':1,'caster':2,'lancer':10,'accseeion':3}
def displayInventory(inventory):
item_total = 0
for k , v in inventory.items():
print(str(v)+' '+ k)
item_total += v
print('The number of items :' + str(item_total))
displayInventory(stuff)
对于列表stuff = {'saber':1,'caster':2,'lancer':10,'accseeion':3}
结果如下
相关文章推荐
- python程序-->列表到字典的函数,针对好玩游戏物品清单
- 验证视图MAC失败。如果此引用程序由网络场或群集承载,请确保<machineKey>配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerateP>
- 【Python】用Python来实现凑24的程序,续--实现统计功能,列举出所有情况
- python实现测试脚本的关键字统计程序
- python字典作为统计记录工具
- <Think Python>中统计文献单词的处理代码
- 使用python写的代码行数统计程序
- Python生成黑客字典程序(一)
- <python>字典,语句
- 1+2+3。。。+99+100的算法的程序 python
- 使用Gevent程序正常运行出现这个异常KeyError(155880780,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored解决办法
- python写的统计PYTHON文件的(代码行数,空行数,注释行数)小程序
- matlab练习程序(白平衡<灰度世界算法>)
- 小菜开始学习算法(返璞归真->程序=数据结构+算法)
- 写的python小程序:对班级选举结果进行筛选统计
- 第一个python程序-blog数目统计
- Python 写的第一个算法程序,果然很强大
- K&R的名著:<C程序设计语言>小程序总结p117统计关键字
- C++库研究笔记[1] Profile->程序执行时间统计
- 寒假挑战PythonTip(一人一python)总结——算法是程序的灵魂,程序员的心法