首页 > 解决方案 > Python - ELIF 语句不会继续 WHILE 循环

问题描述

在课堂上,我们从一个基础程序开始,并将继续在它的基础上进行构建。我被卡住了,不知道为什么当程序到达 ELIF 语句时它不会像第一个 IF 语句那样返回到 WHILE 循环的开头

print("Great Scott! Marty we need to go back to the future!")
print("Marty, lets do a checklist!")
engine = None
circuit = None

while (engine !=1 and circuit != 1):
    engine = int(input("Engine on or off? Enter 1 for ON or 0 for OFF\n"))
    circuit = int(input("Circuit on or off? Enter 1 for ON or 0 for OFF\n"))

    if (engine == 0 and circuit == 0):
         print("Marty! we have to turn everything on before we can time travel!")
         print("Lets check again!")

    elif (engine == 1 and circuit == 0):
        print("Lets turn on the time cicruit")
        print("Lets check again!")

    elif (engine == 0 and circuit == 1):
        print("Turn on the engine!")
        print("Lets check again!")

    else:
        print("Great! lets start driving")
        speed = 0
        while speed < 88:
            speed = int(input("Whats our current speed?\n"))

            if speed < 88:
                print("We need to go faster!")

            else:
                print("Flux Capacitor Fully Charged")
                print("Marty, where we're going, we dont need roads!")

标签: python

解决方案


实际上只是改变and to or

while (engine !=1 or circuit != 1):

推荐阅读