比赛时间清单和获胜时间

时间:2019-04-06 17:52:00

标签: python arrays list input

将时间存储到名为Chevy []和Ford []的数组中。然后列出每对获胜者,并给出获胜者所经过的秒数。最后,根据获胜最多的球队来宣布哪支球队获胜。

我已经列出了名单,但是我不确定如何做到这一点,这样我就可以从列表中抽出时间来显示每个赛车获胜的人数。例如,第一福特时间与雪佛兰第一时间相比,包括平局的比赛获胜者。然后是所有比赛的总冠军。因此,如果雪佛兰赢得3场比赛,福特赢得4场比赛,那么福特将是整体冠军。

Chevy = []
Ford = []

#this code works so far but the ford loop starts again.
for i in range(8):
    time = float(input("Enter Chevy race time's: "))
    Chevy.append(time)   
    total = 0
    slowest_chevy = Chevy[0]
    fastest_chevy = Chevy[0]
for c in Chevy:
    total = total + c
    if c > slowest_chevy:
        slowest_chevy = c
    if c < fastest_chevy:
        fastest_chevy = c
    print(" The race time's are ",Chevy)
    print("The fastest Chevy time is ",fastest_chevy)
    for j in range(8):
        time = float(input("Enter Ford race time's: "))
        Ford.append(time)   
        total = 0
        slowest_F = Ford[0]
        fastest_F = Ford[0]
    for f in Ford:
        total = total + f
        if f > slowest_F:
            slowest_F = f
        if f < fastest_F:
            fastest_F = f
    print(" The race time's are ",Ford)
    print("The fastest Ford time is ",fastest_F)

def find_winner()#not sure what to put here!

我要输入的内容和结果的示例。

---Input Chevy Times---
Enter time for Chevy Car 1: 5.4
Enter time for Chevy Car 2: 7.2
Enter time for Chevy Car 3: 4.0
Enter time for Chevy Car 4: 9.1
Enter time for Chevy Car 5: 5.8
Enter time for Chevy Car 6: 3.9
Enter time for Chevy Car 7: 6.2
Enter time for Chevy Car 8: 8.1
---Input Ford Times---
Enter time for Ford Car 1: 5.8
Enter time for Ford Car 2: 6.9
Enter time for Ford Car 3: 3.9
Enter time for Ford Car 4: 9.2
Enter time for Ford Car 5: 5.8
Enter time for Ford Car 6: 3.8
Enter time for Ford Car 7: 6.0
Enter time for Ford Car 8: 8.5

#results
And the winners are:
Chevy by 0.4 sec
Ford by 0.3 sec
Ford by 0.1 sec
Chevy by 0.1 sec
Tie!
Ford by 0.1 sec
Ford by 0.2 sec
Chevy by 0.4 sec
And the winning team is: F O R D !

0 个答案:

没有答案