【发布时间】:2015-06-22 06:37:16
【问题描述】:
我在遍历我的字典时遇到问题。程序应该打印字典中每个名字旁边的数字的平均值。谁能帮我弄清楚我做错了什么?以下是我当前的代码:
guest={"Mary":"15", "Joe":"13", "Dustin":"12"}
def CalcAverage(guest):
total = 0.0
numPersons = 0
for key,value in guest.items():
numPersons += len(guest[key])
total = float(sum(guest[value]))
return total/numPersons
print CalcAverage(guest)
【问题讨论】:
标签: python function dictionary iteration