栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python作业帮(大学python题库)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python作业帮(大学python题库)

评委打分:

题目要求:

十个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)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/772501.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号