我想用Python创建一个加权函数。然而,权重的数量是不同的,我需要函数有可选的参数(例如,您可以找到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?你知道吗
谢谢你!你知道吗
最好使用具有重量/体积属性的对象(劳伦斯的帖子)
但要演示如何压缩两个元组:
这可以非常简单地通过元组或列表上的操作来完成:
两个选项:a使用两个列表:
第二种选择是使用字典
相关问题 更多 >
编程相关推荐