python while循环错误

时间:2017-10-27 20:22:00

标签: python loops while-loop

这是我的python代码的一部分。输入不同于c / l / d的字母后,必须询问“有没有动物”。但它不起作用。在我输入不同的字母后,它会问“一小时的速度?”只有一次问这个,然后问我“有没有动物?”

我想在输入不同的字母代码时问我“有没有动物?”

</body>

1 个答案:

答案 0 :(得分:0)

您必须重新排序input

while True:
    type=input("enter the type of animal(cheetah:c,lion:l,deer:d):") 
    if type in ('c', 'd', 'l'):
        speed=float(input("average speed for a hour(km):")
        if type=="c":
            ceetah_count+=1
            total_c_speed+=speed
        elif type=="d":
                deer_count+=1
                total_d_speed+=speed
        else:
            lion_count+=1
            total_l_speed+=speed
        animal_count+=1
        total_speed+=speed
    else:
       answer=input("are there any animals?(yes:y/no:n):)")
       if answer != 'y':
           break