def main(scores): min_score = max_score = scores[0] total = 0 for score in scores: if score > max_score: max_score = score elif score < min_score: min_score = score scores.remove(max_score) scores.remove(min_score) for score in scores: total += score return total / len(scores) if __name__ == '__main__': list1 = [1,2,3,4,5,6,7,8] y = main(list1) print("平均成绩: %.2f"% y)
相关文章
- python使用不定长参数求输入值的和、平均值、最大值和最小值
- 用 C语言实现去掉最大值最小值,再求平均值的算法
- 11.2.4 返回列表中的最大值与最小值函数
- Python列表中存放了20个数据,分别表示20个评委的评分,请编写程序,去掉其中的最高分和最低分,求剩下18个分数的平均值。
- python求列表中数字的最大值最小值及下标
- python怎么用for循环找出最大值_用for循环语句写一个在输入的十个数字中求最大和最小值的python程序应该怎么写?...
- 求四个数的最大值与最小值(只用四个if语句)
- Linux中awk命令正确的求最大值、最小值、平均值、总和
- C#中的DatTable,求某一列的最大值,最小值,平均值,列名是个变量
- Linux中awk命令正确的求最大值、最小值、平均值、总和