题目:定义三个函数,
-
search_by_name(filename: str, word: str)
,返回菜单中的所有菜肴名字,菜肴的名字必须包含word。具体如图:
-
search_by_time(filename: str, prep_time: int)
,返回准备时间小于prep_time
的所有菜肴名字。具体如图:
-
search_by_ingredient(filename: str, ingredient: str)
,返回菜肴需要的食材中有ingredient
的所有菜肴名字和准备时间。具体如图:
代码如下: 若有改进之处,求指点~
# Write your solution here
def read_file(filename:str):
list = []
dish_locate = [0]
with open(filename) as new_file:
for line in new_file:
line = line.strip()
if line != '':
list.append(line)
else: