基本上,我需要为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')