首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试计算利润以返回到我的网站

尝试计算利润以返回到我的网站
EN

Stack Overflow用户
提问于 2020-05-27 15:50:46
回答 1查看 34关注 0票数 0

我正在计算你是否会从一个游戏的两个项目中获利,现在我需要做"NPC购买价格-销售价格* 640",原因是你只能购买640的项目,首先我需要保证金,这就是为什么NPC购买价格-销售价格。

这是我的python的样子:

代码语言:javascript
运行
复制
@app.route('/bresell')
def reSell():
    farmingMerchantPrices = [
        "5",  # cocoa beans
        "12",  # brown mushroom
        "2.33",  # carrot
        "8",  # pumpkin
        "2.33",  # wheat
        "12",  # red mushroom
        "2.33",  # potato
        "4",  # sand
        "5",  # sugar cane
        "2",  # melon
    ]
    farmingMerchantName = [
        "Cocoa Beans",
        "Brown Mushroom",
        "Carrot",
        "Pumpkin",
        "Wheat",
        "Red Mushroom",
        "Potato",
        "Sand",
        "Sugar Cane",
        "Melon"
    ]
    sellPrice = []
    f = requests.get(
        'https://api.hypixel.net/skyblock/bazaar?key=[not allowed to show key]').json()
    for x in farmingProducts:
        sellPrice.append(f["products"][x]["sell_summary"][0]["pricePerUnit"])
    profit = []
    for x in farmingMerchantPrices:
        profit.append(sellPrice - x)
    return render_template('resell.html', farmingMerchantPrices=farmingMerchantPrices, farmingMerchantName=farmingMerchantName, sellPrice=sellPrice, profit=profit)

这是我的HTML:

代码语言:javascript
运行
复制
<tbody>
      {% for name, npcBuy,price,profit in zip(farmingMerchantName,
      farmingMerchantPrices,sellPrice,profit) %}
      <tr>
        <td>{{ name }}</td>
        <td>{{ profit will go here }}</td>
        <td>{{ npcBuy }}</td>
        <td>{{ price }}</td>
      </tr>
      {% endfor %}
    </tbody>

我有点困惑,如果我应该做的数学,在金佳或烧瓶,烧瓶,对吗?而且我有点不确定该怎么做!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-27 16:09:14

要回答你的第一个问题,最好在后端执行任何计算,在那里你的计算是隐藏的和安全的。

根据您的第二个问题,我认为您的代码的唯一问题是您在farmingMerchantPrices中将价格定义为字符串而不是数字。因此,您的问题应该只需像这样更改类型即可解决:

代码语言:javascript
运行
复制
farmingMerchantPrices = [
        5,  # cocoa beans   (5 instead of "5")
        12,  # brown mushroom
        2.33,  # carrot
        8,  # pumpkin
        2.33,  # wheat
        12,  # red mushroom
        2.33,  # potato
        4,  # sand
        5,  # sugar cane
        2,  # melon
    ]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62037994

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档