相当于Python或MYSQL中的Excel Goal Seek函数

时间:2016-05-25 07:22:23

标签: python mysql excel function math

如何使用Python或mysql实现Excel Goal Seek函数?

这是情景:

在我工作的代理商,他们购买物品然后卖给网上商店,这个在线商店应用3种不同的费用,按最终价格计算。 该机构希望在最终价格上赚取固定金额,因此我需要计算最终价格以及他们想要赚取的费用和金额。

我知道他们想要赚取的金额和初始价格,以及%的费用,我不知道我需要以什么价格出售物品以赚取特定金额。

使用excel,他们使用目标搜索功能来计算最终价格,包括所有费用和代理商想要获得的固定金额,我想用python或mysql来做。

EX:

a1 = 270.0$ # This is the price they buy the item
c2 = 3.50$ # This is the shipping Price
c3 = 0.10 # This is the FEE of the store in percentage (10%)
c4 = 0.03 # This is the FEE for the credit card (0.3%)
c5 = 0.35$ # This is the Fixed FEE for the store 0.35$
d1 = 5$ # This is the amount they want to earn when they sell the item
x = ? # This is the final price they need to sell the item for earn d1

感谢您的帮助

1 个答案:

答案 0 :(得分:4)

在Python中,您可以执行以下操作。请注意,formumla可能需要调整

a1 = 270.00  # This is the price they buy the item in $

c2 = 3.50  # This is the shipping Price in $
c3 = 0.10  # This is the FEE of the store in percentage (10%)
c4 = 0.03  # This is the FEE for the credit card (0.3%)
c5 = 0.35  # This is the Fixed FEE for the store $0.35

d1 = 5.00  # This is the amount they want to earn when they sell the item in $
x = 0.00  # This is the final price they need to sell the item for earn d1

while True:
    # Assumed Formula - this may need to be adjusted to match your criteria
    earnt_amount = ((x - a1 - c2) * (1 - c3 - c4)) - c5
    x += 0.01
    if earnt_amount >= d1:
        break

print ('Price "x" should be: {0}'.format(x))