咖啡店牛奶库存管理:Python 代码实战解决采购、消耗与盘点难题
以下是使用 Python 实现的解决方案: ```python class MilkInventory: def __init__(self): self.milk_a_quantity = 0 self.milk_a_purchase_dates = {} self.milk_b_quantity = 0 self.milk_b_purchase_dates = {} def purchase(self, brand_a_quantity, brand_b_quantity): current_day = 1 # 假设当前是第一天 self.milk_a_quantity += brand_a_quantity self.milk_a_purchase_dates[current_day] = brand_a_quantity self.milk_b_quantity += brand_b_quantity self.milk_b_purchase_dates[current_day] = brand_b_quantity def consume(self, quantity): if self.milk_a_quantity + self.milk_b_quantity >= quantity: if self.milk_a_quantity >= quantity: self.milk_a_quantity -= quantity else: remaining_quantity = quantity - self.milk_a_quantity self.milk_a_quantity = 0 self.milk_b_quantity -= remaining_quantity def check_inventory(self): current_day = 3 # 假设当前是第三天 remaining_milk_a = self.milk_a_quantity for day, quantity in self.milk_a_purchase_dates.items(): if current_day - day >= 7: remaining_milk_a -= quantity print(f"品牌 A 牛奶的库存量为: {remaining_milk_a}") inventory = MilkInventory() n = 3 operations = [ "1 Purchas 10 20", "2 cost 10", "3 check" ] for operation in operations: parts = operation.split() if parts[1] == "Purchas": inventory.purchase(int(parts[2]), int(parts[3])) elif parts[1] == "cost": inventory.consume(int(parts[2])) elif parts[1] == "check": inventory.check_inventory() ``` ######[AI写代码神器 | 474点数解答 | 2024-10-31 21:32:27]
- Python 代码:合并食品与家居清单,巧妙去除重复物品!(字节豆包 | 89点数解答 | 2025-03-13 09:12:59)197
- Python 运行报错:urllib3 网络连接创建失败,原因及排查建议(字节豆包 | 161点数解答 | 2024-10-31 00:39:36)450
- 工程师必备!10 种工程日常易用管理工具大揭秘(百度文心 | 346点数解答 | 2023-11-09 18:26:09)288
- Python 实战:学生信息列表转字典、遍历、深拷贝及数据修改全流程(GPT | 422点数解答 | 2024-10-29 15:43:54)407
- Python实战:学生成绩列表转字典,深拷贝与数据修改操作全解析(字节豆包 | 254点数解答 | 2024-10-29 16:01:39)399
- bookmanage 数据库表创建、测试数据添加及多需求 SQL 操作全解析(GPT | 909点数解答 | 2024-06-22 22:25:19)406
- WinForm实现图书管理系统:数据库操作、界面设计与功能全解析(GPT | 1163点数解答 | 2024-06-22 22:26:42)362
- 咖啡店牛奶库存管理:Python 代码实战解决采购、消耗与盘点难题(字节豆包 | 474点数解答 | 2024-10-31 21:32:27)163
- C++ 实现咖啡店鲜牛奶库存管理:操作记录处理与盘点揭秘(字节豆包 | 663点数解答 | 2024-12-29 17:06:34)107
- 咖啡店牛奶库存管理:代码实现、问题分析与改进建议(字节豆包 | 811点数解答 | 2024-12-29 17:09:47)106
- Java调用Python接口中文乱码?设置UTF - 8编码一招解决!(讯飞星火 | 263点数解答 | 2024-06-06 17:07:59)385
- 解决Java调用Python接口中文乱码问题:设置UTF - 8编码全攻略(讯飞星火 | 160点数解答 | 2024-06-06 17:18:39)408