తప్పకుండా! పైథాన్ కోడ్లో రెసిపీ యాప్కి ఉదాహరణ ఇక్కడ ఉంది:
కొండచిలువ# Recipe App
# Define a dictionary to store recipes
recipes = {}
# Define a function to add a new recipe
def add_recipe():
name = input("Enter recipe name: ")
ingredients = input("Enter recipe ingredients (separated by commas): ")
instructions = input("Enter recipe instructions: ")
recipes[name] = {
"ingredients": ingredients.split(","),
"instructions": instructions
}
print(f"Recipe for {name} added successfully!")
# Define a function to display all recipes
def display_recipes():
for name, recipe in recipes.items():
print(f"\n{name}\n{'-' * len(name)}")
print(f"Ingredients: {', '.join(recipe['ingredients'])}")
print(f"Instructions: {recipe['instructions']}")
# Define a function to search for a recipe
def search_recipe():
keyword = input("Enter a keyword to search for: ")
results = []
for name, recipe in recipes.items():
if keyword.lower() in name.lower() or keyword.lower() in recipe['ingredients']:
results.append(name)
if results:
print(f"\nSearch Results for '{keyword}':")
for name in results:
print(f"- {name}")
else:
print(f"No results found for '{keyword}'.")
# Define a function to delete a recipe
def delete_recipe():
name = input("Enter the name of the recipe you want to delete: ")
if name in recipes:
del recipes[name]
print(f"Recipe for {name} deleted successfully!")
else:
print(f"No recipe found for {name}.")
# Define a function to display the menu
def display_menu():
print("\nRecipe App")
print("-" * 30)
print("1. Add a recipe")
print("2. Display all recipes")
print("3. Search for a recipe")
print("4. Delete a recipe")
print("5. Exit")
# Define the main function
def main():
while True:
display_menu()
choice = input("\nEnter your choice: ")
if choice == "1":
add_recipe()
elif choice == "2":
display_recipes()
elif choice == "3":
search_recipe()
elif choice == "4":
delete_recipe()
elif choice == "5":
break
else:
print("Invalid choice. Please try again.")
# Call the main function
if __name__ == "__main__":
main()
ఈ రెసిపీ యాప్ను ఉపయోగించడానికి, కోడ్ని అమలు చేసి, వంటకాలను జోడించడానికి, ప్రదర్శించడానికి, శోధించడానికి లేదా తొలగించడానికి ప్రాంప్ట్లను అనుసరించండి...