笔记整理自B站UPWLB工作生活两不误的个人空间-WLB工作生活两不误个人主页-哔哩哔哩视频教程Python 程序设计题8_哔哩哔哩_bilibili
程序设计题8
Python代码
代码一
n = int(input())
score = map(int, input().split())
# 去掉最高分和最低分的几种思路:
# 第一种,排好序,掐头去尾
new_score = sorted(score)
new_score = new_score[1: -1]
avg = sum(new_score) / len(new_score)
print(f'{avg:.2f}')
print('{:.2f}'.format(avg))
代码二
n = int(input())
score = list(map(int, input().split()))
# 第二种,找出最高分和最低分,删除
score.remove(max(score))
score.remove(min(score))
avg = sum(score) / len(score)
print(f'{avg:.2f}')
输入样例
4
100 99 98 97
输出样例
98.50
注意点
代码一可以不是list对象,但是代码二要是list对象
n = int(input())
score = map(int, input().split())
print(score)
print(list(score))
以上代码运行结果如下
输入
4
100 99 98 97
输出
<map object at 0x000001B6EF436F40>
[100, 99, 98, 97]