• 模拟最终成绩计算过程


    首先输入大于2的整数作为评委人数,然后依次输入每个评委的打分,要求每个分数介于0~100.输入完所有评委打分之后,去掉一个最高分,去掉一个最低分,剩余分数的平均分即为该选手的最终得分

    (1)

    while True:
        try:
            n = int(input('请输入评委人数:'))
            assert n > 2
            # 跳出循环
            break
        except:
            print('必须输入大于2的整数')
            
    # 用来保存所有评委的打分
    scores = []
    
    # 依次输入每个评委的打分
    for i in range(n):
        # 这个循环用来保证用户必须输入0~100的数字
        while True:
            try:
                score = float(input('请输入第{0}个评委的分数:'.format(i+1)))
                assert 0 <= score <= 100
                scores.append(score)
                break
            except:
                print('必须属于0到100之间的实数.')
    # 计算并删除最高分和最低分
    highest = max(scores)
    scores.remove(highest)
    lowest = min(scores)
    scores.remove(lowest)
    # 计算平均分,保留2位小数
    average = round(sum(scores)/len(scores), 2)
    
    formatter = '去掉一个最高分{0}\n去掉一个最低分{1}\n最后得分{2}'
    print(formatter.format(highest, lowest, average))
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    (2)

    while True:
        try:
            n = int(input('请输入评委人数:'))
            assert n > 2
            break
        except:
            print('必须输入大于2的整数')
            
    maxScore, minScore = 0, 100
    total = 0
    for i in range(n):
        while True:
            try:
                score = float(input('请输入第{0}个评委的分数:'.format(i+1)))
                assert 0 <= score <= 100
                break
            except:
                print('必须属于0到100之间的实数.')
                
        total += score
        if score > maxScore:
            maxScore = score
        if score < minScore:
            minScore = score
    average = round((total-maxScore-minScore)/(n-2), 2)
    formatter = '去掉一个最高分{0}\n去掉一个最低分{1}\n最后得分{2}'
    print(formatter.format(maxScore, minScore, average))
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
  • 相关阅读:
    【11.23+11.24】Codeforces 刷题
    python的str.find()用法及实例
    Ansible---playbook 剧本
    万字血书Vue—Vue语法
    一些关于完整小程序项目的优秀开源
    NanoPC-T4 RK3399:uboot cmd与boot加载
    OC RSA加密解密
    .NET Redis限制接口请求频率 滑动窗口算法
    接口、压力测试工具入门指南
    java银行存取款程序设计
  • 原文地址:https://blog.csdn.net/2302_77179144/article/details/133976417