我想在 Python 中创建一个加权函数。但是权重的数量会有所不同,我需要该函数具有可选参数(例如,您可以找到 and 的成本weightA
,weightB
但您也可以找到以上所有内容。
基本功能如下所示:
weightA = 1
weightB = 0.5
weightC = 0.33
weightD = 2
cost = 70
volumeA = 100
volumeB = 20
volumeC = 10
volumeD = 5
def weightingfun (cost, weightA, weightB, volumeA, volumeB):
costvolume = ((cost*(weightA+weightB))/(weightA*volumeA+weightB*volumeB))
return costvolume
如何更改功能,以便例如也可以称量体积 C 和体积 D?
提前谢谢!