Food Ordering System
The code is a simple food order system that allows users to order meals based on a type of cuisine, the available options, then generates an order summary.
The code is a simple food order system that allows users to order meals based on a type of cuisine, the available options, then generates an order summary.
This script simulates a basic food ordering system with two cuisine options: Italian and Indian. It starts by displaying a menu of available dishes based on the user's selected cuisine type. The user can then input the meal they want to order and the quantity. The script verifies if the selected meal is available, and if so, it generates a summary of the order, including the quantity and meal name.
Check out the Codeselect_meal()
Function:select_meal()
. The parameters in the function call for select_meal()
should be swapped because the food_type
and name
are passed in the wrong order. The correct call should be:def create_summary(name, amount, food_type):
order = select_meal(name, food_type)
if order:
return f"You ordered {amount} {name}"
else:
return "Meal not found"
if type_input not in ["Italian", "Indian"]:
print("Invalid food type selected.")
exit()
amount_input
, it should be validated to ensure it's a positive integer:try:
amount = int(amount_input)
if amount <= 0:
print("Please enter a positive number for the amount.")
exit()
except ValueError:
print("Please enter a valid number for the amount.")
exit()
python
menu = {
"Italian": ["Pasta Bolognese", "Pepperoni pizza", "Margherita pizza", "Lasagna"],
"Indian": ["Curry", "Chutney", "Samosa", "Naan"]
}
def find_meal(name, menu):
for food_type, meals in menu.items():
if name in meals:
return name
return None
def display_available_meals(food_type):
if food_type in menu:
print(f"Available {food_type} Meals:")
for item in menu[food_type]:
print(item)
else:
print("Invalid food type")
create_summary()
will fail if the select_meal()
function returns None
because the meal isn't found. The function should be enhanced to handle these cases more gracefully.
The code provides a great starting point for a simple food ordering system. By enhancing input validation, restructuring data storage, and improving error handling, the system can be made more robust, scalable, and user-friendly.