比如说电影评分是{功夫熊猫:3,3,4,1}->reading file
平均分为2.5
需要返回的值一定得是个dictionary
我写的fucntion:
def cal_mean(reading file):
averag_dict = {}
for k ,v in txt_dic.items():
average_dict[k] = sum(v)/len(v)
return averag_dict
bug:TypeError: unsupported operand type(s) for +: 'int' and 'str
麻烦有没有人可以加大下
你这个item用法不对啊,item的出来的不是具体的列表啊,会被认为是字符串,不是整型的啊。用sum(txt_dic["功夫熊猫"])/len(txt_dic["功夫熊猫"])