健康食谱输出:用户输入5种不同的食材,输出它们可能组成的所有菜式名称。
时间: 2024-09-25 08:03:51 浏览: 374
为了实现这个功能,我们可以设计一个基于食材的菜式数据库或者预定义一组常见的组合规则。用户输入五种食材后,我们可以遍历数据库或者规则库,找出所有包含这五种食材的菜式。这是一个简化的示例,假设我们有一些基础的菜品配对:
```python
示例菜单库,每项表示一种食材及对应的菜式
menu_library = { "土豆": ["地三鲜", "土豆烧肉"], "胡萝卜": ["胡萝卜炒肉", "炖胡萝卜"], "青椒": ["青椒炒肉", "蔬菜沙拉"], "猪肉": ["红烧肉", "猪肉炖粉条"], "洋葱": ["洋葱炒蛋", "烤肉串"] }
def generate_recipes(ingredients): possible_recipes = [] for ingredient in ingredients: if ingredient in menu_library: possible_recipes.extend(menu_library[ingredient])
# 去除重复的菜式
unique_recipes = list(set(possible_recipes))
return unique_recipes
用户输入示例
user_input = ["土豆", "胡萝卜", "猪肉", "青椒", "洋葱"]
recipes = generate_recipes(user_input) print("可能组成的菜式有:") for recipe in recipes: print(recipe)
相关推荐


















