import random

lis_score = []

n = int(input("输入评委人数:"))

while n < 3:
    print("评委人数需大于3")

    n = int(input("输入评委人数:"))

player = int(input("比赛人数:"))

while player < 3:
    print("比赛人数需大于4")

    player = int(input("比赛人数:"))


def check_score(score):
    if score >= 0 and score <= 100:

        return score

    else:

        print("分数不合法,重新输入!")


# score = int(input("输入分数:"))

# score = check_score(score)

j = player

name_list = []

while j > 0:

    name = input("输入选手姓名:")

    name_list.append(name)

    i = n

    a = []

    while i > 0:
        score = check_score(int(random.randint(1, 10)))

        a.append(score)

        i -= 1

    avg_score = (sum(a) - min(a) - max(a)) / (n - 2)

    lis_score.append([name, avg_score])

    j -= 1

print(lis_score)

res_list = sorted(lis_score, key=lambda d: d[1], reverse=True)
t = dict(res_list)
print(t)
for i in range(player):
    print("姓名:", name_list[i])

    print("平均分:", lis_score[i][1])

    ll = []

for i in range(player):
    ll.append(lis_score[i][1])

    ll.sort(reverse=True)

print(ll)

运行:

输入评委人数:3
比赛人数:4
输入选手姓名:q
输入选手姓名:w
输入选手姓名:e
输入选手姓名:r
[['q', 4.0], ['w', 2.0], ['e', 9.0], ['r', 7.0]]
{'e': 9.0, 'r': 7.0, 'q': 4.0, 'w': 2.0}
姓名: q
平均分: 4.0
姓名: w
平均分: 2.0
姓名: e
平均分: 9.0
姓名: r
平均分: 7.0
[9.0, 7.0, 4.0, 2.0]

Process finished with exit code 0

还有另一个版本的歌手大赛评委打分:

https://blog.csdn.net/weixin_46427623/article/details/122053433

Python十佳歌手一 N个评委给选手打分,去掉1个最高分和1个最低分……

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐