【问题标题】:My While loop does not work as intended in the code我的 While 循环无法按代码中的预期运行
【发布时间】:2022-12-11 19:37:18
【问题描述】:
print ("Welcome To Femboii's Restaraunt")
Name = input ("What's Your Name Sir?\n").capitalize()
EvilGuys = ["Jack", "Ben", "Maria"]
if Name in EvilGuys:
    Evil_Status = input ("Are You Evil " + Name + "?\n").capitalize()
    if Evil_Status == "Yes":
        Good_Deeds = input ("How Many Good Deeds Have You Done Today " + Name + "?\n")
        Bad_Deeds = input ("How Many Bad Deeds Have You Done Today " + Name + "?\n")
        Good_Deeds = int(Good_Deeds)
        Bad_Deeds = int(Bad_Deeds)
    elif Evil_Status == "No":
        print ("Oh, So You Aren't Evil, Come In You're Welcome!")
    else:
        print ("Sorry I Didn't Understand You, So Ill Just Take It As A No")
    if Good_Deeds >= Bad_Deeds:
        print ("Oh, So You Aren't Evil, Come In You're Welcome!")
    if Good_Deeds < Bad_Deeds:
        print ("GET OUTTTT RIGHT NOWWWWWWWWWW!!!!!!!!!!")
        exit ()
print ("Welcome " + Name)
FoodMenu = ("Pizza, Crepe, Burger And Shawrma.")
DrinksMenu = ("Black Coffee, Latte, Mocha, Espresso, Crapuccino And Sparkling Water")
FoodMenuList = ["Pizza", "Crepe", "Burger", "Shawrma"]
DrinksMenuList = ["Black Coffee", "Latte", "Mocha", "Espresso", "Crapuccino", "Sparkling Water"]
Order = input ("Here's Our Food Menu\n" + FoodMenu + "\nAnd Here's Our Drinks Menu\n" + DrinksMenu + "\nChoose What Serves You The Best.\n").capitalize
while Order not in FoodMenuList or Order not in DrinksMenuList:
    if Order in FoodMenuList or Order in DrinksMenuList:
        break
    if Order not in FoodMenuList or Order not in DrinksMenuList:
        input ("Sorry, I Didn't Understand What You Said, Can You Repeat?\n").capitalize()
print (Order)

我试着做到这一点,如果他要的东西不在菜单中,我会告诉他代码是 ai 随便什么

无法理解他,如果他继续这样做,它会继续说

Sorry, I Didn't Understand What You Said, Can You Repeat

并且 while 循环不会停止

【问题讨论】:

  • 你的意思是Order not in FoodMenuList and Order not in DrinksMenuListand而不是or

标签: python python-3.x


【解决方案1】:
while not (Order in FoodMenuList or Order in DrinksMenuList:
    if Order in FoodMenuList or Order in DrinksMenuList:
        break
    if not (Order in FoodMenuList or Order in DrinksMenuList):
        input ("Sorry, I Didn't Understand What You Said, Can You Repeat?
").capitalize()
print (Order)

大概跟逻辑有关。你看:

not P and not Q != not (P and Q) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 2019-01-01
    • 2015-10-10
    相关资源
    最近更新 更多