Skip to main content
 首页 » 编程设计

Python 循环一直错误返回,我该如何修改

2025年05月04日22lexus

<分区>

sandwichType="" 
totalCost=0 
sandwiches=["Baguette", "Bagel", "Sub", "Wrap", "White"] 
sandwichVAL={"Baguette":3.50, "Bagel":2.10, "Sub":3.99, "Wrap":4.15, "White":0.90} 
choice="" 
while choice!="Baguette" or choice!="Bagel" or choice!="Sub" or choice!="Wrap" or choice!="White": 
  choice=str(input("What type of sandwich would you like?\n>Baguette - £3.50\n>Bagel    - £2.10\n>Sub      - £3.99\n>Wrap     - £4.15\n>White    - £0.90\n")) 
  if choice!="Baguette" or choice!="Bagel" or choice!="Sub" or choice!="Wrap" or choice!="White": 
    print("Unfortunately, that is not a valid choice! Please pick again and remember to capitalise the first letter!") 
  else: 
    print() 
totalCost+=sandwichVAL[choice] 
print(totalCost) 

此代码不断返回

Unfortunately, that is not a valid choice! Please pick again and remember to capitalise the first letter! 

即使选择变量是正确的。我应该进行哪些编辑才能打印出总成本?