python这种递归怎么写
[{'Material': '3612622283548', 'Customername': 'CAP 175 HF AO Barrier 2020', 'Deliverydate': '2024-01-04 00:00:00', 'Needqty': 32000.0}, {'Material': '3612622283548', 'Customername': 'CAP 175 HF AO Barrier 2020', 'Deliverydate': '2024-01-08 00:00:00', 'Needqty': 31000.0}, {'Material': '3612622283548', 'Customername': 'CAP 175 HF AO Barrier 2020', 'Deliverydate': '2024-01-15 00:00:00', 'Needqty': 32000.0}][{'Material': '3612622283548', 'Liability': '待完成', 'Orderid': 'XM72-20-23110247', 'Orderqty': 31311.0}, {'Material': '3612622283548', 'Liability': '待完成', 'Orderid': 'XM72-20-23120084', 'Orderqty': 63945.0}]
上面的哪行是到货信息分别是客户料号 客户名称 到货日期 到货数量
下面哪行是订单信息 分别是客户料号 订单号 订单数量
现在的需求是 把订单信息分配到到货信息里面 根据到货信息里面的到货日期 一次 从订单信息里面分配过去 用的哪个订单 分配了多少数量 分配第一个订单分配完了就分配第二个订单
这样的递归函数怎么写呢
为啥会是递归呢,不应该是遍历么 devilpanama 发表于 2023-12-18 10:35
为啥会是递归呢,不应该是遍历么
遍历也行 只要实现就行 为啥会是递归呢,不应该是遍历么。。。。用循环函数for sai609 发表于 2023-12-18 10:53
为啥会是递归呢,不应该是遍历么。。。。用循环函数for
能帮忙写个python实例么 你这个用xlookup不就能实现吗 用xlookup应该能实现的 # 定义日期和入库数量的字典
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 -= remaining_quantity
fulfilled = True
break
else:
print(f" Date: {date}, Quantity: {stock}")
remaining_quantity -= stock
inventory = 0
if not fulfilled:
print(f" Insufficient inventory to fulfill order {order}")
--来自GPT 看了半天好像明白了楼主需求,就是一个货物进库出库的需求。写一个简单的仓库管理系统即可。还有一个细节问题,若α订单用到了A、B两个到货单(A分配前几个订单后残留的尾部+B的头部),该怎么写呢,写两条吗? 楼主,我们要学会使用别人已经造好的轮子。
【对不起,我不应该说教】
现在我用pandas模块的merge函数作一演示:
import pandas as pd
# 导入pandas模块
vara = [{'Material': '3612622283548', 'Customername': 'CAP 175 HF AO Barrier 2020', 'Deliverydate': '2024-01-04 00:00:00', 'Needqty': 32000.0}, {'Material': '3612622283548', 'Customername': 'CAP 175 HF AO Barrier 2020', 'Deliverydate': '2024-01-08 00:00:00', 'Needqty': 31000.0}, {'Material': '3612622283548', 'Customername': 'CAP 175 HF AO Barrier 2020', 'Deliverydate': '2024-01-15 00:00:00', 'Needqty': 32000.0}]
varb = [{'Material': '3612622283548', 'Liability': '待完成', 'Orderid': 'XM72-20-23110247', 'Orderqty': 31311.0}, {'Material': '3612622283548', 'Liability': '待完成', 'Orderid': 'XM72-20-23120084', 'Orderqty': 63945.0}]
# 对变量进行赋值
dfa = pd.DataFrame(vara)
dfb = pd.DataFrame(varb)
# 将上述变量转化为DataFrame
print(pd.merge(dfa,dfb,on = 'Material'))
# 对两个DataFrame进行合并
'''
输出结果如下: 是否是您所需要的?
Material Customername DeliverydateNeedqty Liability OrderidOrderqty
03612622283548CAP 175 HF AO Barrier 20202024-01-04 00:00:0032000.0 待完成XM72-20-23110247 31311.0
13612622283548CAP 175 HF AO Barrier 20202024-01-04 00:00:0032000.0 待完成XM72-20-23120084 63945.0
23612622283548CAP 175 HF AO Barrier 20202024-01-08 00:00:0031000.0 待完成XM72-20-23110247 31311.0
33612622283548CAP 175 HF AO Barrier 20202024-01-08 00:00:0031000.0 待完成XM72-20-23120084 63945.0
43612622283548CAP 175 HF AO Barrier 20202024-01-15 00:00:0032000.0 待完成XM72-20-23110247 31311.0
53612622283548CAP 175 HF AO Barrier 20202024-01-15 00:00:0032000.0 待完成XM72-20-23120084 63945.0
'''
页:
[1]