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

标签 python mysql excel function math

我将如何实现 Excel Goal Seek使用 Python 或 mysql 运行?

这是场景:

在我工作的代理商中,他们购买商品然后卖给在线商店,这家在线商店收取 3 种不同的费用,根据最终价格计算。 该机构希望根据最终价格赚取固定金额,因此我需要用费用和他们想要赚取的金额来计算最终价格。

我知道他们想赚多少钱和初始价格,以及以 % 表示的费用,我不知道我需要以什么价格出售这些元素才能赚取特定金额。

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

例如:

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

谢谢你的帮助

最佳答案

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

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

关于python - 相当于 Python 或 MYSQL 中的 Excel Goal Seek 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37430361/

相关文章:

python - 如何使用 openpyxl 更快地访问单元格值?

php - jQuery/JavaScript : How to get the nth pair in a group of pairs?

mysql - 尝试编写复杂的查询来检索数据

Excel 匹配,索引 VLOOKUP 多个条件

excel - 仅清除包含公式的单元格

python - 如何使用多重处理来删除非常大的列表中的重复项?

python - uint8 与 int64 的链接操作

php - Laravel Excel 将设置值导出到单元格?

python - Pyspark S3 错误 : java. lang.NoClassDefFoundError: com/amazonaws/services/s3/model/MultiObjectDeleteException

mysql - 获取 'cannot add foreign key constraint' 错误