简体   繁体   English

为什么当我在 RobotQ1 输入中输入“YES”时用户输入仍然通过循环?

[英]Why the user input still go through the loop while I'm entering "YES" to the RobotQ1 input?

Basically, once the user has decide to entered "YES" as per the RobotQ1 variable, I want the code to start again, however, it goes through the 2nd user input which RobotQ2.基本上,一旦用户决定根据 RobotQ1 变量输入“YES”,我希望代码重新启动,但是,它会通过第二个用户输入哪个 RobotQ2.

restart = "Yes".lower()
while restart == "YES".lower():
         print(" In order to obtain the harmonized code of your item answer all the following questions")
         print()
         print("Q1 : Does your car have 4 wheel drive")
         RobotQ1 = input("YES / NO ?:")
         if RobotQ1 == "YES".lower():
            print("Here is the HS code:...")
            restart = input("Do you want to use the application? (Yes / No): ")         
         if restart =="NO".lower():
            print("bye")
            break
         elif RobotQ1 == "NO".lower():
            print("Q2 : Does your Robot have 7 axes ?")
         RobotQ2 = input("YES / NO ?:")   
         if RobotQ2 == "YES".lower():
            print("Here is the HS code:....")
            restart = input("Do you want to use the application? (Yes / No): ")
         if restart =="NO".lower():
            print("bye")
            break

So you want to start over your loop without breaking out, in this case:所以你想在不中断的情况下重新开始你的循环,在这种情况下:

Add continue添加continue

The continue statement in Python returns the control to the beginning of the current loop. Python 中的 continue 语句将控制权返回到当前循环的开头。 When encountered, the loop starts next iteration without executing the remaining statements in the current iteration.遇到时,循环开始下一次迭代,而不执行当前迭代中的剩余语句。

Basically You want is基本上你想要的是

if RobotQ1 is Yes==> Give HS Code and ask for Restart如果 RobotQ1 是 Yes==> 提供 HS 代码并要求重新启动

if Robot Q1 is No ==> Ask 7 Axes (if Yes) ==> give Hs Code ==> Ask For Restat如果机器人 Q1 是 No ==> Ask 7 Axes (if Yes) ==> 给出 Hs Code ==> Ask For Restat

I Think Here is Nice One我认为这里很好

restart = "Yes".lower()

while restart == "Yes".lower():
    print(" In order to obtain the harmonized code of your item answer all the following questions")
    print()
    print("Q1 : Does your car have 4 wheel drive")
    RobotQ1 = input("Yes/No ?:")

    if RobotQ1.lower() == "Yes".lower():
        print("Here is the HS Code ...")
    else:
        print("Q2 : Does your Robot have 7 axes ?")
        RobotQ2 = input("Yes/No")
        if RobotQ2.lower() == "Yes".lower():
            print("Here is Hs Code")

    restart = input("Do you want to use the application? (Yes / No): ")
    restart.lower()

    if restart == "No".lower():
        print("bye")
        break

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM