[Python] 纯文本查看 复制代码 # 定义日期和入库数量的字典
inventory = {
'2023-01-01': 70400,
'2023-01-02': 79200,
'2023-01-03': 30800,
'2023-01-04': 79200,
'2023-01-05': 49280,
'2023-01-06': 158400,
'2023-01-07': 317680,
'2023-01-08': 158400,
'2023-01-09': 79200,
'2023-01-10': 158400,
'2023-01-11': 80080,
'2023-01-12': 79200,
'2023-01-13': 158400,
'2023-01-14': 158400
}
# 定义字典存储订单号和订单数量
orders = {
'订单1': 73920,
'订单2': 171600,
'订单3': 54560,
'订单4': 274560,
'订单5': 288640,
'订单6': 316800,
'订单7': 168960,
'订单8': 308000
}
# 根据库存数量拆分订单
for order, quantity in orders.items():
remaining_quantity = quantity
print(f"Order: {order}")
fulfilled = False
for date, stock in inventory.items():
if stock > 0:
if stock >= remaining_quantity:
print(f" Date: {date}, Quantity: {remaining_quantity}")
inventory[date] -= remaining_quantity
fulfilled = True
break
else:
print(f" Date: {date}, Quantity: {stock}")
remaining_quantity -= stock
inventory[date] = 0
if not fulfilled:
print(f" Insufficient inventory to fulfill order {order}")
--来自GPT |