books = { "B001": {"name": "Python编程", "author": "张三", "stock": 5}, "B002": {"name": "数据结构 ", "author": "李四", "stock": 3}, "B003": {"name": "算法导论 ", "author": "王五", "stock": 0} } borrow_records = [ {"book_id": "B001", "book_name": "Python编程", "quantity": 1, "date": "2026-03-25"}, {"book_id": "B002", "book_name": "数据结构", "quantity": 2, "date": "2026-03-26"} ] while True: print("\n菜单:") print("1. 查看所有图书") print("2. 借书") print("3. 还书") print("4. 查询借阅情况") print("5. 退出") choice = input("请选择功能 (1-5): ") if choice == '1': print("\n所有图书:") print("书号\t\t\t\t书名\t\t\t\t作者\t\t\t\t\t库存") print("-" * 55) for book_id, info in books.items(): print(f"{book_id}\t\t{info['name']}\t\t\t{info['author']}\t\t\t\t\t{info['stock']}") print("-" * 55) elif choice == '2': book_id = input("请输入书号: ") if book_id not in books: print("书号不存在。") continue quantity_str = input("请输入借阅数量: ") if not quantity_str.isdigit(): print("借阅数量必须是正整数。") continue quantity = int(quantity_str) if quantity <= 0: print("借阅数量必须大于0。") continue if books[book_id]['stock'] < quantity: print("库存不足。") continue books[book_id]['stock'] -= quantity borrow_records.append({ "book_id": book_id, "book_name": books[book_id]['name'], "quantity": quantity, "date": "2026-04-05" }) print("借书成功。") elif choice == '3': book_id = input("请输入书号: ") if book_id not in books: print("书号不存在。") continue quantity_str = input("请输入归还数量: ") if not quantity_str.isdigit(): print("归还数量必须是正整数。") continue quantity = int(quantity_str) if quantity <= 0: print("归还数量必须大于0。") continue total_borrowed = sum(record['quantity'] for record in borrow_records if record['book_id'] == book_id) if quantity > total_borrowed: print("归还数量大于该书的借出总量。") continue books[book_id]['stock'] += quantity remaining = quantity i = 0 while i < len(borrow_records): if borrow_records[i]['book_id'] == book_id: if borrow_records[i]['quantity'] <= remaining: remaining -= borrow_records[i]['quantity'] borrow_records.pop(i) else: borrow_records[i]['quantity'] -= remaining break else: i += 1 print("还书成功。") elif choice == '4': book_id = input("请输入书号: ") if book_id not in books: print("书号不存在。") continue total_borrowed = sum(record['quantity'] for record in borrow_records if record['book_id'] == book_id) print(f"\n书号 {book_id} 被借出的总数量: {total_borrowed}") print("借阅记录:") for record in borrow_records: if record['book_id'] == book_id: print(f" 借阅数量: {record['quantity']}, 借阅日期: {record['date']}") elif choice == '5': print("退出系统。") break else: print("无效选择,请重新输入。")python 第二次作业
张小明
前端开发工程师
在超大数据集下 DuckDB 与 MySQL 查询速度对比俗
一、什么是urllib3? urllib3 是一个用于处理 HTTP 请求和连接池的强大、用户友好的 Python 库。 它可以帮助你: 发送各种 HTTP 请求(GET, POST, PUT, DELETE等)。 管理连接池,提高网络请求效率。 处理重试和重定向。 支…
如何用XXMI启动器一站式管理六大热门二次元游戏模组?
如何用XXMI启动器一站式管理六大热门二次元游戏模组? 【免费下载链接】XXMI-Launcher Modding platform for GI, HSR, WW and ZZZ 项目地址: https://gitcode.com/gh_mirrors/xx/XXMI-Launcher 你是否厌倦了为每款游戏单独安装和管理模组?是否曾因…
OpenClaw云端体验方案:Qwen3-14B镜像一键部署实践
OpenClaw云端体验方案:Qwen3-14B镜像一键部署实践 1. 为什么选择云端体验OpenClaw 上周我在本地笔记本上折腾OpenClaw时,被Python版本冲突和CUDA依赖折磨得够呛。正当准备放弃时,偶然发现星图平台提供了Qwen3-14BOpenClaw的预置镜像组合。这…
3分钟学会:如何通过手机号码快速定位地理位置?
3分钟学会:如何通过手机号码快速定位地理位置? 【免费下载链接】location-to-phone-number This a project to search a location of a specified phone number, and locate the map to the phone number location. 项目地址: https://gitcode.com/gh_…
django基于数据挖掘的高考志愿推荐系统的设计与实现_3ri592gf_zl033
前言&emsp高考志愿填报是每位高考生必须面对的重要环节,它直接关系到考生的未来学习和职业发展。然而,由于高考志愿的复杂性和多样性,很多考生在填报志愿时感到困惑和迷茫。传统的志愿填报方式主要依赖学校老师的经验、招生简章和家长的经…
MTK设备救砖终极指南:使用MTKClient快速修复联发科设备
MTK设备救砖终极指南:使用MTKClient快速修复联发科设备 【免费下载链接】mtkclient MTK reverse engineering and flash tool 项目地址: https://gitcode.com/gh_mirrors/mt/mtkclient MTKClient是一款专业的联发科芯片底层刷机和修复工具,能够直…