'str'对象无法解释最快单圈时间

时间:2017-05-20 04:10:27

标签: python python-3.x

total = 0
fastest=9999
slowest=0
laps = input("How many laps?")
for i in range(laps):
    lap_time = input("Please enter laptime?")
    if lap_time > fastest:
        fastest = lap_time
    elif lap_time < slowest:
        slowest = lap_time
    total = total + lap_time
print("fastest =>",fastest)
print("slowest =>",slowest)
print("total =>",total)
print("average =>",total/laps)

我收到了类型错误     我在范围内(圈): TypeError:'str'对象不能解释为整数

有人可以帮助我,我是新的

由于

1 个答案:

答案 0 :(得分:0)

当你从input得到一个值时,它被解释为一个字符串,一个字符值。

要将值用作整数,请执行

laps = int(input("How many laps?"))