def pingjun(L=[]):
a=reduce(lambda x,y:x+y,L)
return a*1.0/len(L)
L=[]
for i in range(0,10):
num=input('enter your score:')
L.append(int(num))
L.remove(max(L))
L.remove(min(L))
print(pingjun(L))这个函数并不能去掉最大值,而且求平均值的函数会报错,求解
5 回答
刘小米92
TA贡献8条经验 获得超14个赞
#最大数 def Get_Max(list): return max(list) #最小数 def Get_Min(list): return min(list) #极差 def Get_Range(list): return max(list) - min(list) #中位数 def get_median(data): data = sorted(data)size = len(data) if size % 2 == 0: # 判断列表长度为偶数 median = (data[size//2]+data[size//2-1])/2 if size % 2 == 1: # 判断列表长度为奇数 median = data[(size-1)//2] return median #众数(返回多个众数的平均值) def Get_Most(list): most=[] item_num = dict((item, list.count(item)) for item in list)for k,v in item_num.items(): if v == max(item_num.values()): most.append(k) return sum(most)/len(most) #获取平均数 def Get_Average(list): sum = 0 for item in list: sum += item return sum/len(list)
添加回答
举报
0/150
提交
取消