簡體   English   中英

為什么我的 while 循環不能正常工作?

[英]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")

While 循環中的這段代碼中,當我輸入 Yes 或 yes 或 No 或 no 時,它應該消除循環,並且如果我輸入 Yes,它應該從你想訂購的開頭開始,當我輸入 No 時它應該消除所有循環並打印好的,但它不是請幫我解決這個問題

repeat.= "No" 或repeat.= "no"... 測試總是結果為True,變量不能同時為No 和no,如果repeat not 在["No", "no" " 中使用是的是的”]

感謝https://stackoverflow.com/users/271415/jarmod的回答

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM