查看并运用初始代码,其中已定义一个列表canteen存储深职院各校区所有饭堂的信息,列表中每家饭堂信息利用字典存储,字典含有五个键值对,包括有饭堂名称('dname')、好评星级('stars')、座位数('seats')、网红菜名("kol_dish")和餐厅负责人("manager"),其中网红菜名又是按列表存储。 字典代码 canteen=[ {"dname":"南门食堂", "seats":760,"kol_dish":["汤粉","排骨串","烫菜"],"stars":"四星","manager":"李主管"} ,{"dname":"北区食堂","seats":676,"kol_dish":["多味屋","五香鱼粉","牛腩粉","瓦罐汤"],"stars":"五星","manager":"王主管"} ,{"dname":"教工食堂","seats":1200,"kol_dish":["小炒","麻辣烫","酸菜鱼","牛肉面"],"stars":"三星","manager":"张主管"} ,{"dname":"柳园餐厅","seats":1910,"kol_dish":["扒虾","木桶饭","鸡扒饭","云吞","焖菜"],"stars":"四星","manager":"罗主管"} ,{"dname":"锦园学生餐厅","seats":3250,"kol_dish":["牛杂","机器人刀削面","饭煲","饺子"],"stars":"五星","manager":"贺主管"} ,{"dname":"民族风味餐厅","seats":120,"kol_dish":["大盘鸡","兰州拉面","烤馕","新疆拌面"],"stars":"五星","manager":"买买提主管"} ] 请继续编程实现:当用户输入要查询的网红菜名称后,查询输出相关饭堂名称等信息;查询不到时输出“无此网红菜名”。 输入和输出要求例如: 请输入网红菜名:云吞 欢迎来 柳园餐厅 品尝 云吞 或者: 请输入网红菜名:烧饼 无此网红菜名pc代码
时间: 2023-08-10 07:05:13 浏览: 606
canteen=[ {"dname":"南门食堂", "seats":760,"kol_dish":["汤粉","排骨串","烫菜"],"stars":"四星","manager":"李主管" } , {"dname":"北区食堂","seats":676,"kol_dish":["多味屋","五香鱼粉","牛腩粉","瓦罐汤"],"stars":"五星","manager":"王主管" } , {"dname":"教工食堂","seats":1200,"kol_dish":["小炒","麻辣烫","酸菜鱼","牛肉面"],"stars":"三星","manager":"张主管" } , {"dname":"柳园餐厅","seats":1910,"kol_dish":["扒虾","木桶饭","鸡扒饭","云吞","焖菜"],"stars":"四星","manager":"罗主管" } , {"dname":"锦园学生餐厅","seats":3250,"kol_dish":["牛杂","机器人刀削面","饭煲","饺子"],"stars":"五星","manager":"贺主管" } , {"dname":"民族风味餐厅","seats":120,"kol_dish":["大盘鸡","兰州拉面","烤馕","新疆拌面"],"stars":"五星","manager":"买买提主管" } ]
dish = input("请输入网红菜名:")
exist = False
for canteen_item in canteen:
if dish in canteen_item["kol_dish"]:
exist = True
print("欢迎来", canteen_item["dname"], "品尝", dish)
if not exist:
print("无此网红菜名")
阅读全文