Python:每日一题 219
本帖最后由 冬雪雪冬 于 2018-12-19 19:12 编辑我们的玩法做了一下改变:
1. 楼主不再提供答案。
2. 请大家先独立思考,再参考其他鱼油的解答,这样才有助于自己编程水平的提高。开始阶段是看不到其他人的回帖的,等答题完成,开始评分时再取消限制。
3. 鼓励大家积极答题,奖励的期限为出题后24小时内。
4. 根据答案的质量给予1~3鱼币的奖励。
题目:
今天来一道简单的题目,很多主观性评分的比赛,是由多个裁判评分,最终去掉1个最高分,去掉1个最低分,取其它分数的平均值。
编写一个函数fun219,参数为3个以上的分数,按上述规则return返回平均分。
注,采用收集参数来接收不定个数的数值。
例如:
fun219(95, 33, 72, 88, 98, 45, 66, 72)
返回73.0
=================================================
希望大家能帮我想一些题目,具体的要求是:
1.难度适中
2.充分利用python的特性
3.最好是自己想出来的
如果有合适的题目,请给我发消息或直接发帖并@我对于出题的鱼油给予奖励。 def fun219(*parms):
l = []
for each in parms:
l.append(each)
return (sum(l)-max(l)-min(l))/(len(l) -2)
if __name__ == '__main__':
print(fun219(95, 33, 72, 88, 98, 45, 66, 72)) 本帖最后由 塔利班 于 2018-12-12 17:48 编辑
def fun219(*x):
if len(x)<3:
print('请输入3个以上数据')
else:
return round(sum(sorted(x))/(len(x)-2),1)
def fun219(*args):
result = list()
avg = 0
for i in args:
result.append(i)
result.remove(max(result))
result.remove(min(result))
for i in result:
avg += i/len(result)
return avg
if __name__ == '__main__':
print(fun219(95, 33, 72, 88, 98, 45, 66, 72)) def fun219(*args):
return print((sum(args)-max(args)-min(args))/(len(args)-2))
fun219(95, 33, 72, 88, 98, 45, 66, 72) def fun219(*scores):
max_index = max(range(len(scores)), key=scores.__getitem__)
min_index = min(range(len(scores)), key=scores.__getitem__)
return sum( for i in filter(lambda x:False if x == max_index or \
x == min_index else True,\
range(len(scores)))]) / (len(scores)-2) def fun219(*scores):
if len(scores < 3):
return 0
max_index = max(range(len(scores)), key=scores.__getitem__)
min_index = min(range(len(scores)), key=scores.__getitem__)
return sum( for i in filter(lambda x:False if x == max_index or \
x == min_index else True,\
range(len(scores)))]) / (len(scores)-2)
没仔细读题{:10_266:} def fun219(a):
del a
del a
print("平均分为:",'%.2f'%(sum(a)/len(a)))
fun219()
fun219()
def func219(*param):
return round(sum(sorted(param)[ 1:-1 ]) / (len(param) - 2), 1) def fun219(*num):
sum_num = 0
for i in range(len(num)):
sum_num += num
sum_num = sum_num - min(num) - max(num)
return sum_num/(len(num) - 2)
def fun219(*scores):
scores=list(scores)
scores.remove(max(scores))
scores.remove(min(scores))
return sum(scores)/len(scores) def fun219(*arg):
print((sum(arg)-max(arg)-min(arg))/(len(arg)-2))
def fun219(*n):
k=list(n)
k.remove(max(n))
k.remove(min(n))
return sum(k)/len(k)
print(fun219(95, 33, 72, 88, 98, 45, 66, 72))
import numpy
def fun219(*args):
list1 =
list1.remove(max(list1))
list1.remove(min(list1))
return numpy.mean(list1)
print(fun219(95, 33, 72, 88, 98, 45, 66, 72)) def func219(*args):
if len(args)>=3:
list_1 = list(args)
a = min(list_1)
b = max(list_1)
list_1.remove(a)
list_1.remove(b)
sum = 0
for i in list_1:
sum =sum + i
returnsum/len(list_1)
else:
return '输入的参数少于三个!!'
print(func219(90,34,4,56,43,12,34)) def fun219(*param):
return (sum(param) - max(param) - min(param))/(len(param)-2)
print(fun219(95, 33, 72, 88, 98, 45, 66, 72)) list=
def fun219(list):
sum=0
list.remove(min(list))
list.remove(max(list))
for x in list:
sum+=x
return sum/len(list)
print(fun219(list)) #从键盘获取数值,并存入数组
a = []
while True:
a_list = input("请输入分数,按q结束:")
if a_list != 'q':
a.append(a_list)
else:
break
#求平均值
def fun219(a):
a1 = a2 = a
summ = 0
count = 0
for i in a:
if i > a1:
a1 = i
if i < a2:
a2 = i
for j in a:
if j !=a1:
if j != a2:
summ += int(j)
count += 1
av = summ / count
return av
def fun219(*nums):
return sum(sorted(nums))/(len(nums) - 2) if len(nums) > 2 else None
print(fun219(95, 33, 72, 88, 98, 45, 66, 72)) def fun219(*args):
print("初始为:",end='')
print(args)
print("按降序排序后为:", end='')
max_sort=sorted(args,reverse=True)
print(max_sort)
max_sort.pop(0)
max_sort.pop(-1)
print("去掉最大值和最小值后为:", end='')
print(max_sort)
sum=0
avg=0
for i inmax_sort:
sum=sum+i
avg=sum/len(max_sort)
print("平均值为:"+str(avg))
fun219(95, 33, 72, 88, 98, 45, 66, 72)