代码未显示列表的所有顺序并导致 SyntaxError
Code is not displaying all of the order to the list and causes SyntaxError
此程序旨在询问客户的订单,然后在最后显示他们的订单。
出于某种原因,我的代码无法正常工作 - 并且还会导致 SyntaxError
。我已经显示了以下代码的计划:
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 Italian, Indian or Chinese food?\n")
if foodGroup == "italian" or foodGroup == "Italian":
dish = input("Do you want Pasta or Pizza?\n")
if dish == "pizza":
dish = input("Do you want Grilled chicken or Seasonal vegetables?\n")
if dish == "seasonal vegetables":
order.insert(1,dish)
if dish == "grilled chicken":
order.insert(1,dish)
if dish == "pasta":
dish = input("Do you want Vegetarian Toppings or meat toppings?\n")
if dish == "Vegetarian Toppings":
order.insert(1,dish)
if dish == "meat toppings":
order.insert(1,dish)
if foodGroup == "indian" or foodGroup == "Indian":
dish = input("Do you want Curry or onion bhaji?\n")
if dish == "Curry":
dish = input("Do you want Rice or Naan?\n")
if dish == "Rice":
order.insert(1,dish)
if dish == "Naan":
order.insert(1,dish)
if dish == "onion bhaji":
dish = input("Do you want Chilli or Peppers?\n")
if dish == "Chilli":
order.insert(1,dish)
if dish == "Peppers":
order.insert(1,dish)
if foodGroup == "chinese" or foodGroup == "Chinese":
dish = input("Do you want Chicken Wings or onion Noodles?\n")
if dish == "Chicken Wings":
dish = input("Do you want Chips or Red peppers?\n")
if dish == "Chips":
order.insert(1,dish)
if dish == "Red peppers":
order.insert(1,dish)
if dish == "Noodles":
dish = input("Do you want Meatballs or Chicken?\n")
if dish == "Meatballs":
order.insert(1,dish)
if dish == "Chicken":
order.insert(1,dish)
print ("You have ordered",order"enjoy your meal")
代码应该是这样工作的:
提示用户选择饮料,然后选择美食,然后选择菜肴。
此后,程序显示用户想要的顺序。
好吧,我已经 运行 了代码,无效的语法就在最后一行:
order = []
>>> print ("You have ordered",order"enjoy your meal")
SyntaxError: invalid syntax
改为print ("You have ordered", order ,"enjoy your meal")
>>> print ("You have ordered", order ,"enjoy your meal")
('You have ordered', [], 'enjoy your meal')
编辑:似乎有效:
>>>
Welcome to Hungary house.
Do you want a drink?
"yes"
What drink would you prefer?
1: Fanta
2: Coke
3: Pepsi
4: Sprite
please select a drink from the options above
"1"
you have chosen this drink: Fanta
Do you want Italian, Indian or Chinese food?
"indian"
Do you want Curry or onion bhaji?
"Curry"
Do you want Rice or Naan?
"Rice"
('You have ordered', ['Fanta', 'Rice'], 'enjoy your meal')
您没有看到 "Curry" 因为您实际上并没有将其添加到订单中,而只是 "Rice" 配菜...
此程序旨在询问客户的订单,然后在最后显示他们的订单。
出于某种原因,我的代码无法正常工作 - 并且还会导致 SyntaxError
。我已经显示了以下代码的计划:
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 Italian, Indian or Chinese food?\n")
if foodGroup == "italian" or foodGroup == "Italian":
dish = input("Do you want Pasta or Pizza?\n")
if dish == "pizza":
dish = input("Do you want Grilled chicken or Seasonal vegetables?\n")
if dish == "seasonal vegetables":
order.insert(1,dish)
if dish == "grilled chicken":
order.insert(1,dish)
if dish == "pasta":
dish = input("Do you want Vegetarian Toppings or meat toppings?\n")
if dish == "Vegetarian Toppings":
order.insert(1,dish)
if dish == "meat toppings":
order.insert(1,dish)
if foodGroup == "indian" or foodGroup == "Indian":
dish = input("Do you want Curry or onion bhaji?\n")
if dish == "Curry":
dish = input("Do you want Rice or Naan?\n")
if dish == "Rice":
order.insert(1,dish)
if dish == "Naan":
order.insert(1,dish)
if dish == "onion bhaji":
dish = input("Do you want Chilli or Peppers?\n")
if dish == "Chilli":
order.insert(1,dish)
if dish == "Peppers":
order.insert(1,dish)
if foodGroup == "chinese" or foodGroup == "Chinese":
dish = input("Do you want Chicken Wings or onion Noodles?\n")
if dish == "Chicken Wings":
dish = input("Do you want Chips or Red peppers?\n")
if dish == "Chips":
order.insert(1,dish)
if dish == "Red peppers":
order.insert(1,dish)
if dish == "Noodles":
dish = input("Do you want Meatballs or Chicken?\n")
if dish == "Meatballs":
order.insert(1,dish)
if dish == "Chicken":
order.insert(1,dish)
print ("You have ordered",order"enjoy your meal")
代码应该是这样工作的: 提示用户选择饮料,然后选择美食,然后选择菜肴。 此后,程序显示用户想要的顺序。
好吧,我已经 运行 了代码,无效的语法就在最后一行:
order = []
>>> print ("You have ordered",order"enjoy your meal")
SyntaxError: invalid syntax
改为print ("You have ordered", order ,"enjoy your meal")
>>> print ("You have ordered", order ,"enjoy your meal")
('You have ordered', [], 'enjoy your meal')
编辑:似乎有效:
>>>
Welcome to Hungary house.
Do you want a drink?
"yes"
What drink would you prefer?
1: Fanta
2: Coke
3: Pepsi
4: Sprite
please select a drink from the options above
"1"
you have chosen this drink: Fanta
Do you want Italian, Indian or Chinese food?
"indian"
Do you want Curry or onion bhaji?
"Curry"
Do you want Rice or Naan?
"Rice"
('You have ordered', ['Fanta', 'Rice'], 'enjoy your meal')
您没有看到 "Curry" 因为您实际上并没有将其添加到订单中,而只是 "Rice" 配菜...