[go: up one dir, main page]

0% found this document useful (0 votes)
240 views7 pages

Recipe Finder Project With Index

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views7 pages

Recipe Finder Project With Index

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Index

1. Project Overview ............................................................. 1

2. Part 1: Recipe Database ....................................................... 2

3. Part 2: Adding a New Recipe .............................................. 3

4. Part 3: Finding Recipes Based on Ingredients .................. 4

5. Part 4: Main Program (User Interface) ............................... 5

6. Full Program Code ............................................................. 6

7. Viva Key Points ................................................................. 7

Recipe Finder Project for Class 12 Computer


Science

Project Overview
The Recipe Finder project helps users find recipes they can make with ingredients they already
have. The program contains a list of recipes with ingredients and lets users either add a new
recipe or search for recipes based on available ingredients.

Project Code
Below is the code, split into simple parts with explanations.

Part 1: Recipe Database


Here, we create a dictionary to store recipes. Each key is the recipe name, and each value is a list
of ingredients required.

# Recipe Database

recipes = {

"Pancakes": ["flour", "milk", "egg", "sugar", "baking powder"],


"Omelette": ["egg", "salt", "pepper", "onion", "tomato"],

"Pasta": ["pasta", "tomato sauce", "garlic", "olive oil"],

"Salad": ["lettuce", "tomato", "cucumber", "olive oil", "lemon"],

"Smoothie": ["banana", "milk", "honey", "ice"]

 Explanation: This recipes dictionary is like a mini recipe book. Each recipe has a list of
ingredients needed to make it.

Part 2: Adding a New Recipe


This function allows the user to add a new recipe with a name and list of ingredients.

# Function to add a new recipe

def add_recipe(recipe_name, ingredients):

if recipe_name in recipes:

print(f"{recipe_name} already exists in the database.")

else:

recipes[recipe_name] = ingredients

print(f"{recipe_name} has been added.")

 Explanation: add_recipe() checks if the recipe already exists. If it does, it shows a


message; otherwise, it adds the new recipe to the recipes dictionary.

Part 3: Finding Recipes Based on Ingredients


This function allows the user to input ingredients they have, and it checks which recipes can be
made with those ingredients.

# Function to find recipes based on available ingredients


def find_recipes(available_ingredients):

matching_recipes = []

for recipe, ingredients in recipes.items():

if all(item in available_ingredients for item in ingredients):

matching_recipes.append(recipe)

if matching_recipes:

print("You can make the following recipes:")

for recipe in matching_recipes:

print(f"- {recipe}")

else:

print("No recipes found with the given ingredients.")

 Explanation: find_recipes() goes through each recipe and checks if all ingredients
are available. If a recipe matches, it’s added to a list of recipes the user can make. If
no recipes match, a message is shown.

Part 4: Main Program (User Interface)


This section handles user choices, letting them add a recipe, search for recipes, or exit.

# Main program loop

def main():

print("Welcome to the Recipe Finder!")

while True:

print("\nOptions:")

print("1. Add a new recipe")

print("2. Find recipes based on available ingredients")

print("3. Exit")
choice = input("Enter your choice (1/2/3): ")

if choice == "1":

recipe_name = input("Enter the name of the recipe: ")

ingredients = input("Enter the ingredients (comma-separated): ").split(",")

ingredients = [item.strip() for item in ingredients] # Remove extra whitespace

add_recipe(recipe_name, ingredients)

elif choice == "2":

available_ingredients = input("Enter the ingredients you have (comma-separated):


").split(",")

available_ingredients = [item.strip() for item in available_ingredients]

find_recipes(available_ingredients)

elif choice == "3":

print("Exiting the Recipe Finder. Happy cooking!")

break

else:

print("Invalid choice. Please try again.")

 Explanation:

1. The main() function displays options to the user: add a recipe, search for recipes, or
exit.

2. Based on the choice, it calls the appropriate function: add_recipe() or find_recipes().

3. The program runs in a loop until the user decides to exit.

Full Program Code

Here’s the full, simplified code to copy into your Word document:

python
# Recipe Database

recipes = {

"Pancakes": ["flour", "milk", "egg", "sugar", "baking powder"],

"Omelette": ["egg", "salt", "pepper", "onion", "tomato"],

"Pasta": ["pasta", "tomato sauce", "garlic", "olive oil"],

"Salad": ["lettuce", "tomato", "cucumber", "olive oil", "lemon"],

"Smoothie": ["banana", "milk", "honey", "ice"]

# Function to add a new recipe

def add_recipe(recipe_name, ingredients):

if recipe_name in recipes:

print(f"{recipe_name} already exists in the database.")

else:

recipes[recipe_name] = ingredients

print(f"{recipe_name} has been added.")

# Function to find recipes based on available ingredients

def find_recipes(available_ingredients):

matching_recipes = []

for recipe, ingredients in recipes.items():

if all(item in available_ingredients for item in ingredients):

matching_recipes.append(recipe)

if matching_recipes:

print("You can make the following recipes:")

for recipe in matching_recipes:


print(f"- {recipe}")

else:

print("No recipes found with the given ingredients.")

# Main program loop

def main():

print("Welcome to the Recipe Finder!")

while True:

print("\nOptions:")

print("1. Add a new recipe")

print("2. Find recipes based on available ingredients")

print("3. Exit")

choice = input("Enter your choice (1/2/3): ")

if choice == "1":

recipe_name = input("Enter the name of the recipe: ")

ingredients = input("Enter the ingredients (comma-separated): ").split(",")

ingredients = [item.strip() for item in ingredients] # Remove extra whitespace

add_recipe(recipe_name, ingredients)

elif choice == "2":

available_ingredients = input("Enter the ingredients you have (comma-separated):


").split(",")

available_ingredients = [item.strip() for item in available_ingredients]

find_recipes(available_ingredients)

elif choice == "3":

print("Exiting the Recipe Finder. Happy cooking!")


break

else:

print("Invalid choice. Please try again.")

# Run the program

if __name__ == "__main__":

main()

Viva Key Points

1. Dictionary Use: Explain how the recipes dictionary stores recipes as keys and ingredients
as values.

2. Functions: add_recipe() adds recipes, and find_recipes() checks for matching recipes.

3. Loop Control: main() uses a loop to allow repeated actions until the user exits.

4. Conditionals: Different actions are taken based on user choices (adding recipes, searching,
exiting).

This structured breakdown should make it easier to understand and edit for a Word document
and viva preparation.

You might also like