-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1
More file actions
78 lines (63 loc) · 2.21 KB
/
1
File metadata and controls
78 lines (63 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import json
FILE_NAME = "recipes.json"
def load_recipes():
try:
with open(FILE_NAME, "r") as f:
return json.load(f)
except FileNotFoundError:
return []
def save_recipes(recipes):
with open(FILE_NAME, "w") as f:
json.dump(recipes, f, indent=4)
def add_recipe(recipes):
name = input("Enter recipe name: ").strip()
ingredients = input("Enter ingredients (comma separated): ").strip()
instructions = input("Enter cooking instructions: ").strip()
recipe = {
"name": name,
"ingredients": [i.strip().lower() for i in ingredients.split(",")],
"instructions": instructions
}
recipes.append(recipe)
print(f"✅ Recipe '{name}' added.")
def view_recipes(recipes):
if not recipes:
print("📭 No recipes found.")
return
print("\n📋 All Recipes:")
for i, recipe in enumerate(recipes, 1):
print(f"{i}. {recipe['name']}")
def search_by_ingredient(recipes):
ingredient = input("Enter ingredient to search for: ").strip().lower()
found = [r for r in recipes if ingredient in r['ingredients']]
if not found:
print(f"🔍 No recipes found with ingredient '{ingredient}'.")
return
print(f"\n🔍 Recipes containing '{ingredient}':")
for i, recipe in enumerate(found, 1):
print(f"{i}. {recipe['name']}")
print(f" Ingredients: {', '.join(recipe['ingredients'])}")
print(f" Instructions: {recipe['instructions']}")
def main():
recipes = load_recipes()
while True:
print("\n=== RecipeBuddy – Recipe Manager & Search ===")
print("1 - Add recipe")
print("2 - View all recipes")
print("3 - Search recipes by ingredient")
print("4 - Exit")
choice = input("Choose an option: ").strip()
if choice == "1":
add_recipe(recipes)
save_recipes(recipes)
elif choice == "2":
view_recipes(recipes)
elif choice == "3":
search_by_ingredient(recipes)
elif choice == "4":
print("👩🍳 Happy cooking! Goodbye!")
break
else:
print("❌ Invalid option. Try again.")
if __name__ == "__main__":
main()