Py学习  »  Python

如何列出参加python比赛的参赛者的姓名、时间和位置?

Alando123 • 4 年前 • 283 次点击  

基本上,我需要为4个组创建一个参与者列表(我想对这些组进行排序),记录他们在比赛中的时间和排名,并生成一个格式整洁的结果表。

racers = [(i, l[i]) for i in l]

places = sorted(racers, key = lambda i: int(i[1]))

print('1st Place: {}'.format(places[0][0]))
print('2nd Place: {}'.format(places[1][0]))
print('3rd Place: {}'.format(places[2][0]))

这是我当前的代码:

l = []
a = int(input("Enter the amount of racers for Anstey: "))
g = int(input("Enter the amount of racers for Gordon: "))
h = int(input("Enter the amount of racers for Helps: "))
r = int(input("Enter the amount of racers for Rawle: "))
total_racers = a+g+h+r

print("Total Racers:",total_racers)

for i in range(total_racers):
  racer_name = (input("Participant Name: "))
  racer_time = int(input("Participant Time: "))
  time_name = racer_time,racer_name
  l.append(time_name)

print('\n',*l, sep='\n')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53152
 
283 次点击  
文章 [ 2 ]  |  最新文章 4 年前