比较细节】Python歌手大赛2,请了N个评委给选手打分(随机生成),输入选手名字、输入评委人数等,分数排大小
import randomlis_score = []n = int(input("输入评委人数:"))while n < 3:print("评委人数需大于3")n = int(input("输入评委人数:"))player = int(input("比赛人数:"))while player < 3:print("比赛人数需大于4")player = int(input("比赛人数:"
·
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个最低分……
更多推荐
已为社区贡献2条内容
所有评论(0)