干饭随心选系统

news2026/3/18 21:00:56
1. 字典模块数据存储字典嵌套是处理 “结构化多维度数据” 的核心方式比如 “饭馆” 作为一个实体包含多个属性用内层字典封装更清晰列表适合存储 “有序的序列数据”如历史记录、菜单字典适合存储 “键值对的映射数据”如饭馆属性。# 干饭随心选系统 print(\n\n 干饭随心选系统 ) # 使用字典存储更详细的饭馆信息 restaurants_dict { 川菜馆: { 类型: 川菜, 电话: 123-4567, 菜单: [麻婆豆腐, 水煮鱼, 宫保鸡丁, 回锅肉], 价格区间: 中等, 评分: 4.5, 营业时间: 11:00-22:00 }, 粤菜馆: { 类型: 粤菜, 电话: 234-5678, 菜单: [白切鸡, 烧鹅, 叉烧, 虾饺], 价格区间: 偏高, 评分: 4.3, 营业时间: 10:30-21:30 }, 湘菜馆: { 类型: 湘菜, 电话: 345-6789, 菜单: [剁椒鱼头, 毛氏红烧肉, 辣椒炒肉], 价格区间: 中等, 评分: 4.2, 营业时间: 11:00-23:00 }, 日料店: { 类型: 日料, 电话: 456-7890, 菜单: [寿司拼盘, 刺身, 拉面, 天妇罗], 价格区间: 偏高, 评分: 4.7, 营业时间: 11:30-22:00 }, 西餐厅: { 类型: 西餐, 电话: 567-8901, 菜单: [牛排, 意大利面, 沙拉, 披萨], 价格区间: 偏高, 评分: 4.4, 营业时间: 11:00-23:00 }, 火锅店: { 类型: 火锅, 电话: 678-9012, 菜单: [麻辣火锅, 清汤火锅, 鸳鸯锅], 价格区间: 中等, 评分: 4.6, 营业时间: 10:00-24:00 } } # 历史选择记录 lunch_history [] dinner_history []1字典设计逻辑渐进初级阶段如果是新手入门可能先只用 “单层字典” 存储基础信息比如 restaurants {川菜馆: 123-4567, 粤菜馆: 234-5678}只能存 “名称 - 电话”无法承载多维度信息。进阶阶段采用 “嵌套字典 列表” 的结构化设计外层字典key饭馆名称value该饭馆的所有信息内层字典实现 “按名称快速查找”内层字典key信息维度类型/电话/菜单等value对应值其中 “菜单” 用列表存储多菜品适配 “多个值” 的场景历史记录用列表 lunch_history [ ] 、dinner_history [ ] 存储利用列表 “有序、可重复、支持 append/remove” 的特性记录选择顺序。2. 函数功能模块业务逻辑函数模块整体设计思路所有函数遵循 “单一职责原则”—— 一个函数只做一件事。功能点增删改查查询饭馆信息def show_all_restaurants(): 显示所有饭馆详细信息 print(\n所有饭馆详细信息:) for name, info in restaurants_dict.items(): print(f\n{name}:) print(f 类型: {info[类型]}) print(f 电话: {info[电话]}) print(f 菜单: {, .join(info[菜单])}) print(f 价格: {info[价格区间]}) print(f 评分: {info[评分]}) print(f 营业时间: {info[营业时间]})修改饭馆详情def modify_restaurant(): 修改饭馆信息 print(\n修改饭馆信息:) # 先显示所有饭馆供用户选择 if not restaurants_dict: print(当前系统中没有饭馆信息) return print(当前系统中的饭馆:) for i, name in enumerate(restaurants_dict.keys(), 1): print(f{i}. {name}) restaurant_name input(\n请输入要修改的饭馆名称: ) if restaurant_name in restaurants_dict: print(f\n当前 {restaurant_name} 的信息:) info restaurants_dict[restaurant_name] print(f类型: {info[类型]}) print(f电话: {info[电话]}) print(f菜单: {, .join(info[菜单])}) print(f价格区间: {info[价格区间]}) print(f评分: {info[评分]}) print(f营业时间: {info[营业时间]}) print(\n请输入新的信息直接回车保持原值:) new_type input(f类型 [{info[类型]}]: ) or info[类型] new_phone input(f电话 [{info[电话]}]: ) or info[电话] new_menu_input input(f菜单 [{, .join(info[菜单])}]: ) new_menu new_menu_input.split(,) if new_menu_input else info[菜单] new_price input(f价格区间 [{info[价格区间]}]: ) or info[价格区间] new_score_input input(f评分 [{info[评分]}]: ) new_score float(new_score_input) if new_score_input else info[评分] new_hours input(f营业时间 [{info[营业时间]}]: ) or info[营业时间] # 更新信息 restaurants_dict[restaurant_name] { 类型: new_type, 电话: new_phone, 菜单: new_menu, 价格区间: new_price, 评分: new_score, 营业时间: new_hours } print(f成功更新 {restaurant_name} 的信息) else: print(f未找到名为 {restaurant_name} 的饭馆)删除现有饭馆def delete_restaurant(): 删除饭馆 print(\n删除饭馆:) # 先显示所有饭馆供用户选择 if not restaurants_dict: print(当前系统中没有饭馆信息) return print(\n删除方式:) print(1. 按名称删除单个饭馆) print(2. 按条件批量删除) delete_choice input(请选择删除方式1-2: ) if delete_choice 1: # 单个删除逻辑 print(\n当前系统中的饭馆:) for i, name in enumerate(restaurants_dict.keys(), 1): print(f{i}. {name}) restaurant_name input(\n请输入要删除的饭馆名称: ) if restaurant_name in restaurants_dict: # 确认删除 confirm input(f确定要删除 {restaurant_name} 吗(y/n): ) if confirm.lower() y: del restaurants_dict[restaurant_name] print(f成功删除 {restaurant_name}) # 同时从历史记录中删除 if restaurant_name in lunch_history: lunch_history.remove(restaurant_name) if restaurant_name in dinner_history: dinner_history.remove(restaurant_name) else: print(取消删除操作) else: print(f未找到名为 {restaurant_name} 的饭馆) elif delete_choice 2: # 批量删除逻辑这里需要倒序遍历 print(\n批量删除条件:) print(1. 按类型删除) print(2. 按价格区间删除) print(3. 按评分删除) batch_choice input(请选择批量删除条件1-3: ) restaurants_to_delete [] if batch_choice 1: type_filter input(请输入要删除的类型川菜/粤菜/湘菜/日料/西餐/火锅: ) restaurants_to_delete [name for name, info in restaurants_dict.items() if info[类型] type_filter] elif batch_choice 2: price_filter input(请输入要删除的价格区间中等/偏高: ) restaurants_to_delete [name for name, info in restaurants_dict.items() if info[价格区间] price_filter] elif batch_choice 3: max_score float(input(请输入最高评分删除评分低于此值的饭馆: )) restaurants_to_delete [name for name, info in restaurants_dict.items() if info[评分] max_score] else: print(无效选择) return if not restaurants_to_delete: print(没有找到符合条件的饭馆) return print(f\n找到 {len(restaurants_to_delete)} 家符合条件的饭馆:) for i, name in enumerate(restaurants_to_delete, 1): print(f{i}. {name}) confirm input(f\n确定要删除这 {len(restaurants_to_delete)} 家饭馆吗(y/n): ) if confirm.lower() y: # 这里需要倒序遍历列表来安全删除 deleted_count 0 for i in range(len(restaurants_to_delete)-1, -1, -1): name restaurants_to_delete[i] del restaurants_dict[name] # 同时从历史记录中删除 if name in lunch_history: lunch_history.remove(name) if name in dinner_history: dinner_history.remove(name) deleted_count 1 print(f已删除: {name}) print(f\n成功批量删除 {deleted_count} 家饭馆) else: print(取消批量删除操作) else: print(无效选择)添加新饭馆信息def add_new_restaurant(): 添加新饭馆 print(\n添加新饭馆:) name input(饭馆名称: ) type_ input(饭馆类型: ) phone input(联系电话: ) menu input(菜单用逗号分隔: ).split(,) price input(价格区间中等/偏高: ) score float(input(评分0-5: )) hours input(营业时间: ) restaurants_dict[name] { 类型: type_, 电话: phone, 菜单: menu, 价格区间: price, 评分: score, 营业时间: hours } print(f成功添加 {name} 到系统)智能推荐防重复机制避免连续推荐同一饭馆根据时间午餐/晚餐自动推荐饭馆def smart_recommendation(meal_type, history): 智能推荐饭馆避免重复选择 import random # 获取所有饭馆名称 all_restaurants list(restaurants_dict.keys()) # 如果历史记录为空随机选择 if not history: return random.choice(all_restaurants) # 避免最近选择的饭馆 recent_choices history[-3:] # 最近3次选择 available_choices [r for r in all_restaurants if r not in recent_choices] # 如果所有饭馆都在最近选择过则从所有中选择 if not available_choices: available_choices all_restaurants return random.choice(available_choices) def select_meal(meal_type, history): 智能选择餐食午餐/晚餐 selected_name smart_recommendation(meal_type, history) selected_info restaurants_dict[selected_name] history.append(selected_name) print(f\n{meal_type}智能推荐: {selected_name}) print(f类型: {selected_info[类型]}) print(f电话: {selected_info[电话]}) print(f推荐菜单: {, .join(selected_info[菜单])}) print(f价格区间: {selected_info[价格区间]}) print(f评分: {selected_info[评分]}) print(f营业时间: {selected_info[营业时间]})按条件筛选支持按菜系、价格、评分等条件筛选def filter_restaurants(): 按条件筛选饭馆 print(\n筛选条件:) print(1. 按类型筛选) print(2. 按价格筛选) print(3. 按评分筛选) filter_choice input(请选择筛选方式1-3: ) if filter_choice 1: type_filter input(请输入类型川菜/粤菜/湘菜/日料/西餐/火锅: ) filtered {name: info for name, info in restaurants_dict.items() if info[类型] type_filter} elif filter_choice 2: price_filter input(请输入价格区间中等/偏高: ) filtered {name: info for name, info in restaurants_dict.items() if info[价格区间] price_filter} elif filter_choice 3: min_score float(input(请输入最低评分0-5: )) filtered {name: info for name, info in restaurants_dict.items() if info[评分] min_score} else: print(无效选择) return if filtered: print(f\n找到 {len(filtered)} 家符合条件的饭馆:) for name, info in filtered.items(): print(f{name}: {info[类型]}, 评分{info[评分]}, 价格{info[价格区间]}) else: print(未找到符合条件的饭馆)查看历史记录提供历史数据查询功能记录用户访问和推荐历史def show_selection_history(): 显示选择历史 print(\n午餐选择历史:) for i, restaurant in enumerate(lunch_history, 1): print(f{i}. {restaurant}) print(\n晚餐选择历史:) for i, restaurant in enumerate(dinner_history, 1): print(f{i}. {restaurant})3. 主程序循环模块交互入口用户交互界面核心。菜单式循环交互主菜单选项查看饭馆信息智能推荐午餐/晚餐按条件筛选查看历史记录管理饭馆添加、删除、修改退出系统循环逻辑用户选择后返回菜单直至退出# 主程序循环 while True: print(\n *60) print(欢迎使用干饭随心选系统) print(1. 查看所有饭馆详细信息) print(2. 智能选择午餐避免重复) print(3. 智能选择晚餐避免重复) print(4. 按条件筛选) print(5. 查看选择历史) print(6. 添加新饭馆) print(7. 删除饭馆) print(8. 修改饭馆信息) print(9. 退出系统) choice input(请选择功能1-9: ) if choice 1: show_all_restaurants() elif choice 2: select_meal(午餐, lunch_history) elif choice 3: select_meal(晚餐, dinner_history) elif choice 4: filter_restaurants() elif choice 5: show_selection_history() elif choice 6: add_new_restaurant() elif choice 7: delete_restaurant() elif choice 8: modify_restaurant() elif choice 9: print(感谢使用干饭随心选系统再见) break else: print(无效选择请重新输入1-9)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2424110.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…