简体   繁体   中英

Why is my while loop not working properly?

import time



burger=0
mcpuff=0
icecream=0
coldrink=0
repeat=0
price=0
print("Welcome to McDonald's self order system")
time.sleep(0.5)
name_person=str(input("\nPlease enter your name to continue: "))
while True:
    order=int(input("\n---Menu---\n 1.Burger\n 2.McPuff\n 3.Ice Cream\n 4.Cold Drink\n\nPlease order by typing the number: "))
    if order in range(1,5) :
        order_amount=int(input("Please enter the amount you want to order: "))
        if order == 1 :
            burger=burger+order_amount
        elif order == 2 :
            mcpuff=mcpuff+order_amount
        elif order == 3 :
            icecream=icecream+order_amount
        elif order == 4 :
            coldrink=coldrink+order_amount
        while repeat != "No" or repeat != "no" or repeat != "Yes" or repeat != "yes" :
            repeat=str(input("Do you want to order more? Yes/No: "))
            if repeat in ("Yes", "yes", "No", "no") :
                if repeat == "No" or repeat == "no":
                    print("Ok")
                    break
            else :
                print("\n!!Invalid input!!")
                time.sleep(0.5)
    else :
        print("\n!!Invalid input!!")
        time.sleep(0.5)
print("Ok")

In this code in the While loop when I will type Yes or yes or No or no it should eliminate the loop and in that also if I type Yes it should start from the starting of do you want to order and when i type No it should eliminate the all loop and print Ok but its not please help me in this problem

The repeat.= "No" or repeat.= "no"... test always results in True, The variable cannot be both No and no at the same time, Use if repeat not in ["No", "no" "Yes" "yes"]

Thanks to https://stackoverflow.com/users/271415/jarmod for the answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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