【Python入门|文科生也能学会的Python】趣味习题-评委打分

编程知识 更新时间:2023-04-07 08:43:52

评委打分:

题目要求

十个10评委打分,去掉一个最高分,去掉一个最低分,求平均分。

简单的版本不要求实现控制台输入分数

数据(直接写在程序里)

list=[90,89,91,92, 93,96,87,89, 90,91];

加分项

实现分数从控制台输入

解题:

if __name__ == '__main__':
    scores = [90, 89, 91, 92, 93, 96, 87, 89, 90, 91]
	scores.remove(max(scores))
    scores.remove(min(scores))
    mean = sum(scores) / 8
    print(mean)

没有max和min:手动找max和min

if __name__ == '__main__':
    scores = [90, 89, 91, 92, 93, 96, 87, 89, 90, 91]
	maxScore = scores[1]
	minScore = scores[1]
    for item in scores:
        if item > maxScore:
            maxScore = item
        if item < minScore:
            minScore = item
	scores.remove(maxScore)
    scores.remove(minScore)
    mean = sum(scores) / 8
	print(mean)

sorted来实现

if __name__ == '__main__':
    scores = [90, 89, 91, 92, 93, 96, 87, 89, 90, 91]
    newScore = sorted(scores)
    newScore.pop(0)
    newScore.pop(8)
    mean = sum(newScore) / 8
    print(mean)

实现分数从控制台输入:

if __name__ == '__main__':
    scores = []
    for n in range (1, 11):
        print("请输入第%d个评委的打分:"%(n))
        score = int(input())
        scores.append(score)
    print(scores)
    scores.remove(max(scores))
    scores.remove(min(scores))
    mean = sum(scores) / 8
    print(mean)

更多推荐

【Python入门|文科生也能学会的Python】趣味习题-评委打分

本文发布于:2023-04-07 08:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/88355a9dbf39409a53e325309a4324d6.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也能   习题   评委   趣味   入门

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 52957文章数
  • 14阅读数
  • 0评论数