【发布时间】:2016-01-30 19:49:55
【问题描述】:
代码应该是这样工作的:提示用户选择一种饮料,然后是菜肴,然后是菜肴。在此之后,程序显示用户想要的顺序。
问题是,当客户输入他们的详细信息时,最后没有正确显示详细信息。
代码应该做什么显示在代码下方。
print("Welcome to Hungary house.")
addDrink = input("Do you want a drink?\n").lower()
drinkChoice = "None"
dish = ""
order = []
if addDrink == "yes":
print ("What drink would you prefer?")
print ("1: Fanta")
print ("2: Coke")
print ("3: Pepsi")
print ("4: Sprite")
drinkChoice = input("please select a drink from the options above\n")
if drinkChoice == "1" or drinkChoice == "fanta":
drinkChoice = "Fanta"
order.insert(0,drinkChoice)
if drinkChoice == "2" or drinkChoice == "coke":
drinkChoice = "Coke"
order.insert(0,drinkChoice)
if drinkChoice == "3" or drinkChoice == "pepsi":
drinkChoice = "Pepsi"
order.insert(0,drinkChoice)
if drinkChoice == "4" or drinkChoice == "sprite":
drinkChoice = "Sprite"
order.insert(0,drinkChoice)
print ("you have chosen this drink: " + drinkChoice)
foodGroup = input("Do you want Indian or Chinese food?\n").lower()
if foodGroup == "indian" or foodGroup == "Indian":
dish = input("Do you want Curry or onion bhaji?\n").lower()
if dish == "Curry":
order.insert(1,dish)
dish = input("Do you want Rice or Naan?\n").lower()
if dish == "Rice":
order.insert(2,dish)
if dish == "Naan":
order.insert(2,dish)
if dish == "onion bhaji":
order.insert(1,dish)
dish = input("Do you want Chilli or Peppers?\n").lower()
if dish == "Chilli":
order.insert(2,dish)
if dish == "Peppers":
order.insert(2,dish)
if foodGroup == "chinese" or foodGroup == "Chinese":
dish = input("Do you want Chicken Wings or Noodles?\n").lower()
if dish == "Chicken Wings":
order.insert(1,dish)
dish = input("Do you want Chips or Red peppers?\n").lower()
if dish == "Chips":
order.insert(2,dish)
if dish == "Red peppers":
order.insert(2,dish)
if dish == "Noodles":
order.insert(1,dish)
dish = input("Do you want Meatballs or Chicken?\n").lower()
if dish == "Meatballs":
order.insert(2,dish)
if dish == "Chicken":
order.insert(2,dish)
print ("You have ordered the following",order,"You are order number 294")
这段代码的逻辑应该是这样的:
Welcome to Hungary house.
Do you want a drink?
If no, Move on to the next question
If yes, ask what drink the customer wants.
(Coke, Fanta, lemonade are the options)
If coke is chosen, set coke as drink
If Fanta is chosen, set Fanta as drink
If Lemonade is chosen, set Lemonade as drink
你想要印度菜还是中国菜?
If Indian food is entered ask the following questions
Do you want Curry or onion bhaji?
If curry is selected ask the following questions.
What toppings you want on top of your Curry?
Rice
Or
Naan
If user enters rice, add rice on to the curry.
If user enters Naan, add naan on to the curry.
If user enters onion ask the following questions.
What toppings do you want on top of your onion bhaji?
Chilli source
Or
Naan
If user enters Chilli source, add chilli source on to the onion bhaji.
If user enters Naan, add Naan on to the onion bhaji.
.
If Chinese food is entered ask the following questions.
Do you want Chicken wings or Noodles?
If Chicken wings is chosen ask,
Do you want with your Chicken wings?
Green Peppers
Or
Red Peppers
If Green pepper is chosen add that to the Green Peppers to the Chicken wings
If Red Peppers are chosen add that to the Chicken wings.
If the user enters Noodles ask the following questions.
Choose the toppings you want with Noodles.
Meatballs
Or
Chicken
If user enters Meatballs, add Meatballs to the Noodles.
If user enters Chicken, add Chicken to the Noodles.
在此之后,显示用户想要的订单,告诉客户他们的订单将在接下来的 10-50 分钟内到达。如果他们想取消,请告诉他们联系这个号码“077 3475 XXXXXX”。
【问题讨论】:
-
每次使用“or”时,都可以使用“in”:如果drinkChoice == "2"或者drinkChoice == "coke"也可以写成:如果drinkChoice in ["2", “可乐”]
-
这个测试永远不会起作用:dish = input("Do you want Curry or onion bhaji?\n").lower() ....if disc == "Curry" "Curry" cannot当您将用户输入转换为小写时,请使用大写 C。
-
有趣的是,您有设置 yes 和 no 的想法
-
@Luis Sieira 那我该怎么办?
-
@Apero 你能回答这个问题并给我一个例子吗
标签: python list if-statement input