Python 仅返回烧瓶中的正值

Python 仅返回烧瓶中的正值,python,flask,jinja2,Python,Flask,Jinja2,所以我正在做一个项目,一个表格可以告诉你哪些项目可以盈利。问题是我希望它显示大于1的项,也就是所有正值。现在,它展示了你无法从中获利的产品 以下是该网站的图片: 以下是我的python代码: @app.route('/bresell') def reSell(): farmingMerchantPrices = [ 5, # cocoa beans 12, # brown mushroom 2.33, # carrot

所以我正在做一个项目,一个表格可以告诉你哪些项目可以盈利。问题是我希望它显示大于1的项,也就是所有正值。现在,它展示了你无法从中获利的产品

以下是该网站的图片:

以下是我的python代码:

@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=73ac0a44-4c41-4933-a9ee-b4095be2b6d2').json()
    for x in farmingProducts:
        sellPrice.append(f["products"][x]["sell_summary"][0]["pricePerUnit"])

    profit = []
    zip_object = zip(farmingMerchantPrices, sellPrice)
    for farmingMerchantPrices_i, sellPrice_i in zip_object:
        profit.append(sellPrice_i - farmingMerchantPrices_i)
我的return语句在代码的下面

这是我的HTML:

<h1 class="npc-title">Farming Merchant</h1>
  <table
    id="myTable"
    class="table table-striped table-bordered table-sm table-dark"
    cellspacing="0"
  >
    <thead>
      <tr>
        <th aria-label="Product Name" data-balloon-pos="up">Product</th>
        <th aria-label="How much you will earn" data-balloon-pos="up">
          Profit (x640)
        </th>
        <th aria-label="How much you will earn" data-balloon-pos="up">
          Profit (x1)
        </th>
        <th aria-label="NPC buy price" data-balloon-pos="up">
          NPC Buy Price
        </th>
        <th aria-label="Bazaar sell price" data-balloon-pos="up">
          Bazaar Sell Price
        </th>
      </tr>
    </thead>
    <tbody>
      {% for name, npcBuy, price, profit in zip(farmingMerchantName,
      farmingMerchantPrices,sellPrice, profit) %}
      <tr>
        <td>{{ name }}</td>
        {% set profit2 = profit * 640%}
        <td>{{profit2|round(1, 'floor')}}</td>
        <td>{{ profit|round(1, 'floor') }}</td>
        <td>{{ npcBuy|round(1, 'floor') }}</td>
        <td>{{ price }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
农商
产品
利润(x640)
利润(x1)
NPC买入价
集市售价
{%表示名称、npcBuy、价格、zip中的利润(farmingMerchantName、,
农业商品价格、销售价格、利润)%}
{{name}}
{%set profit2=利润*640%}
{{profit2 | round(1,'floor')}
{{利润|轮(1,'楼层')}
{{npcBuy | round(1,'floor')}
{{price}}
{%endfor%}

我不知道怎么做,我想我必须做一个IF语句,检查总利润是否小于1,但正如你所看到的,我在HTML中计算利润

Jinja还允许您在html上使用if语句,因此在html上添加检查利润的if语句应该可以:

<tbody>
  {% for name, npcBuy, price, profit in zip(farmingMerchantName,
  farmingMerchantPrices,sellPrice, profit) %}
  {% if profit > 1 %}
  <tr>
    <td>{{ name }}</td>
    {% set profit2 = profit * 640%}
    <td>{{profit2|round(1, 'floor')}}</td>
    <td>{{ profit|round(1, 'floor') }}</td>
    <td>{{ npcBuy|round(1, 'floor') }}</td>
    <td>{{ price }}</td>
  </tr>
  {% endif %}
  {% endfor %}
</tbody>

{%表示名称、npcBuy、价格、zip中的利润(farmingMerchantName、,
农业商品价格、销售价格、利润)%}
{如果利润>1%,则为%1}
{{name}}
{%set profit2=利润*640%}
{{profit2 | round(1,'floor')}
{{利润|轮(1,'楼层')}
{{npcBuy | round(1,'floor')}
{{price}}
{%endif%}
{%endfor%}

Jinja还允许您在html上使用if语句,因此添加一个if语句检查您在html上的利润应该可以做到:

<tbody>
  {% for name, npcBuy, price, profit in zip(farmingMerchantName,
  farmingMerchantPrices,sellPrice, profit) %}
  {% if profit > 1 %}
  <tr>
    <td>{{ name }}</td>
    {% set profit2 = profit * 640%}
    <td>{{profit2|round(1, 'floor')}}</td>
    <td>{{ profit|round(1, 'floor') }}</td>
    <td>{{ npcBuy|round(1, 'floor') }}</td>
    <td>{{ price }}</td>
  </tr>
  {% endif %}
  {% endfor %}
</tbody>

{%表示名称、npcBuy、价格、zip中的利润(farmingMerchantName、,
农业商品价格、销售价格、利润)%}
{如果利润>1%,则为%1}
{{name}}
{%set profit2=利润*640%}
{{profit2 | round(1,'floor')}
{{利润|轮(1,'楼层')}
{{npcBuy | round(1,'floor')}
{{price}}
{%endif%}
{%endfor%}

假设您只检查
利润
,那么您可以使用
,条件如下:

{%表示名称、npcBuy、价格、zip中的利润(farmingMerchantName、farmingMerchantPrices、sellPrice、利润)%}
{如果利润>1%,则为%1}
{{name}}
{%set profit2=利润*640%}
{{profit2 | round(1,'floor')}
{{利润|轮(1,'楼层')}
{{npcBuy | round(1,'floor')}
{{price}}
{%endif%}
{%endfor%}

假设您只检查
利润
,那么您可以使用
,条件如下:

{%表示名称、npcBuy、价格、zip中的利润(farmingMerchantName、farmingMerchantPrices、sellPrice、利润)%}
{如果利润>1%,则为%1}
{{name}}
{%set profit2=利润*640%}
{{profit2 | round(1,'floor')}
{{利润|轮(1,'楼层')}
{{npcBuy | round(1,'floor')}
{{price}}
{%endif%}
{%endfor%}