简体   繁体   English

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

[英]equivalent of Excel Goal Seek function in Python or MYSQL

How would I implement a Excel Goal Seek function with Python or mysql?我将如何使用 Python 或 mysql 实现Excel Goal Seek函数?

This is the scenario :这是场景:

in the agency where i work they buy items and then sell to an online store, this online store apply 3 different FEES , calculated on the final price.在我工作的代理机构中,他们购买商品然后卖到网上商店,这家网上商店适用 3 种不同的费用,根据最终价格计算。 The agency wants to earn a fixed amount of money on the final price, so i need to calculate the final price with the fees and the amount they want to earn.该机构希望以最终价格赚取固定金额,因此我需要用费用和他们想要赚取的金额来计算最终价格。

I know the amount money they want to earn and the initial price, and the fees in % , i don't know at what price i need to sell the items for earn that specific amount of money.我知道他们想要赚取的金额和初始价格,以及以 % 为单位的费用,我不知道我需要以什么价格出售这些物品才能赚取特定数量的钱。

With excel they use the goal seek function that calculate the final price with all the fees and the fixed amount the agency want to earn, i would like to do it with python or mysql.使用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

Thanks for your help谢谢你的帮助

In Python you could do the following.在 Python 中,您可以执行以下操作。 Note the formumla may need adjusting注意公式可能需要调整

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))

Here is the goalseek equivalent of Excel in Python. 这是Python中Excel的等效目标。 Please see the "ExampleScript.py" to understand how it works. 请查看“ ExampleScript.py”以了解其工作方式。 The link: https://github.com/DrTol/GoalSeek_Python 链接: https//github.com/DrTol/GoalSeek_Python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM