class Recipe:
def __init__(self, name, ingredients, instructions):
self.name = name
self.ingredients = ingredients
self.instructions = instructions
def display(self):
print(f"Recipe Name: {self.name}")
print("\nIngredients:")
for ingredient in self.ingredients:
print(f"- {ingredient}")
print("\nInstructions:")
for instruction in self.instructions:
print(f"- {instruction}")
def find_recipe(name, recipes):
for recipe in recipes:
if recipe.name.lower() == name.lower():
return recipe
return None
def delete_recipe(name, recipes):
for index, recipe in enumerate(recipes):
if recipe.name.lower() == name.lower():
del recipes[index]
return True
return False
recipes = []
while True:
print("\nWelcome to the Recipe Book Manager")
print("Select your action")
print("A: Add a recipe \nB. View a Recipe \nC. Delete a Recipe \nD. Exit")
choice = input("Your Choice: ").upper()
if choice == "A":
recipe_name = input("Enter the name of the recipe: ")
ingredients = []
while True:
ingredient = input("Add an ingredient (or type 'done' to finish): ")
if ingredient.lower() == 'done':
break
ingredients.append(ingredient)
instructions = []
while True:
instruction = input("Enter the process/instructions for the recipe (Type 'done' to finish): ")
if instruction.lower() == "done":
break
instructions.append(instruction)
new_recipe = Recipe(recipe_name, ingredients, instructions)
recipes.append(new_recipe)
print("Recipe added successfully!")
new_recipe.display()
elif choice == "B":
recipe_name = input("Enter the name of the recipe you want to view: ")
recipe = find_recipe(recipe_name, recipes)
if recipe:
recipe.display()
else:
print("Recipe not found!")
elif choice == "C":
action = input("Would you like to Edit (E) or Delete (D) a recipe? ").upper()
if action == "D":
recipe_name = input("Enter the name of the recipe you want to delete: ")
if delete_recipe(recipe_name, recipes):
print("Recipe deleted successfully!")
else:
print("Recipe not found!")
elif choice == "D":
print("Goodbye!")
break
Welcome to the Recipe Book Manager
Select your action
A: Add a recipe
B. View a Recipe
C. Delete a Recipe
D. Exit
Recipe added successfully!
Recipe Name: Garlic Bread
Ingredients:
- Garlic
- Bread
Instructions:
- Take garlic
- take bread
- make garlic bread
Welcome to the Recipe Book Manager
Select your action
A: Add a recipe
B. View a Recipe
C. Delete a Recipe
D. Exit
Recipe Name: Garlic Bread
Ingredients:
- Garlic
- Bread
Instructions:
- Take garlic
- take bread
- make garlic bread
Welcome to the Recipe Book Manager
Select your action
A: Add a recipe
B. View a Recipe
C. Delete a Recipe
D. Exit
Recipe deleted successfully!
Welcome to the Recipe Book Manager
Select your action
A: Add a recipe
B. View a Recipe
C. Delete a Recipe
D. Exit
Welcome to the Recipe Book Manager
Select your action
A: Add a recipe
B. View a Recipe
C. Delete a Recipe
D. Exit
Welcome to the Recipe Book Manager
Select your action
A: Add a recipe
B. View a Recipe
C. Delete a Recipe
D. Exit
Recipe not found!
Welcome to the Recipe Book Manager
Select your action
A: Add a recipe
B. View a Recipe
C. Delete a Recipe
D. Exit
Goodbye!