简体   繁体   中英

equivalent of Excel Goal Seek function in Python or MYSQL

How would I implement a Excel Goal Seek function with Python or mysql?

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

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. 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. Please see the "ExampleScript.py" to understand how it works. The link: https://github.com/DrTol/GoalSeek_Python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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