2024-04-19 19:29:58 发布
网友
def score(numbers): """Return the average of the numbers excluding the biggest and the smallest one""" score([2, 7, 9, 10, 13, 1, 5, 12]) # Answer must be =7.5 score([3, 7, 2.5, -4)] # Answer must be 2.75
请帮忙。你知道吗
def score(l): l = sorted(l) return sum(l[1:-1]) / float(len(l) - 2) print(score([2, 7, 9, 10, 13, 1, 5, 12])) print(score([3, 7, 2.5, -4]))
>>> def score(a): ... a.remove(max(a)) ... a.remove(min(a)) ... print sum(a)/(float(len(a)))
另外,还有一种方法可以得到列表的平均值,你也可以使用这个方法。你知道吗
print reduce(lambda x, y: x + y / float(len(a)), a, 0)
另外,还有一种方法可以得到列表的平均值,你也可以使用这个方法。你知道吗
相关问题 更多 >
编程相关推荐