Python Code for Meal Planner
# Meal Planner Program
def display_meal_plan(meal_plan):
print("\nYour Meal Plan for the Week:")
for day, meals in meal_plan.items():
print(f"{day}: Breakfast: {meals['Breakfast']}, Lunch: {meals['Lunch']}, Dinner: {meals['Dinner']}")
def get_meal_input(day):
breakfast = input(f"Enter Breakfast for {day}: ")
lunch = input(f"Enter Lunch for {day}: ")
dinner = input(f"Enter Dinner for {day}: ")
return {'Breakfast': breakfast, 'Lunch': lunch, 'Dinner': dinner}
def meal_planner():
days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
meal_plan = {}
print("Welcome to the Meal Planner!")
for day in days_of_week:
meal_plan[day] = get_meal_input(day)
display_meal_plan(meal_plan)
if __name__ == "__main__":
meal_planner()
How It Works
- Function Definitions:
display_meal_plan(meal_plan)
: This function prints the meal plan for the week.get_meal_input(day)
: This function prompts the user to input meals for breakfast, lunch, and dinner for a given day.meal_planner()
: The main function that orchestrates the meal planning process.
- User Interaction:
- The program prompts the user to enter meals for each day of the week.
- It then stores the meals in a dictionary and displays the entire meal plan at the end.
Running the Code
To run this code:
- Ensure you have Python installed on your machine.
- Copy the code into a Python file (e.g.,
meal_planner.py
). - Run the file using the command:
python meal_planner.py
.
Customization Ideas
- Save and Load Meal Plans: You can extend the program to save meal plans to a file and load them later.
- Dietary Preferences: Add options for dietary restrictions (e.g., vegetarian, gluten-free).
- Random Meal Suggestions: Implement a feature that suggests meals from a predefined list.
- Nutrition Information: Include a database of meals with nutritional information.
Leave a Reply