#Adyant
validOrders = ("burger", "fries", "salad", "soda", "milkshake")
itemDescriptions = ("Half-pound burger", "Large fries", "Side salad", "Diet root beer", "Chocolate shake" )
order = []
print("Welcome to Burger Castle")
print("Menu:", validOrders)
print("Please enter each item in your order. Press 'Enter' or type 'quit' on an empty line when done.")
while True:
item = input("Enter Item: ")
if item != "" or item != "quit":
break
elif item in validOrders:
order += [item]
else:
print("Sorry, we don't sell " + item)
print("Order complete; you are having:")
for item in order:
index = validOrders.index(item)
description = itemDescriptions[index]
print(description)
print("Thanks for visiting Burger Castle!")
validOrders = ("burger", "fries", "salad", "soda", "milkshake")
itemDescriptions = ("Half-pound burger", "Large fries", "Side salad", "Diet root beer", "Chocolate shake" )
order = []
print("Welcome to Burger Castle")
print("Menu:", validOrders)
print("Please enter each item in your order. Press 'Enter' or type 'quit' on an empty line when done.")
while True:
item = input("Enter Item: ")
if item != "" or item != "quit":
break
elif item in validOrders:
order += [item]
else:
print("Sorry, we don't sell " + item)
print("Order complete; you are having:")
for item in order:
index = validOrders.index(item)
description = itemDescriptions[index]
print(description)
print("Thanks for visiting Burger Castle!")
What is wrong with this code?
1 answer
1. The condition in the while loop should be `if item == "" or item == "quit"` instead of `if item != "" or item != "quit"`. The current condition will always evaluate to True, causing an infinite loop.
2. The code for adding items to the order list should be inside the if statement `elif item in validOrders`, not inside the else statement. As it is currently written, items that are not in the validOrders list will still be added to the order list.