如果是,则Elif和Else在利润计算器应用中无法显示正确的打印值

时间:2018-07-24 02:35:40

标签: python

我是StackOverflow的新手,但是从8岁起我就一直在“和” HTML和CSS交往。我最近学习了Python课程(25岁),并决定使用编程作为扩展。我的职业道路。我正在开发一个小程序,它使我和Shopify电子商务的所有人(在我现在居住的巴西)可以使用用户输入(产品零售价,产品成本,每次转化费用)来计算单个产品的利润率。还应该根据商店/供应商无息融资产品的次数(parcelas)来显示利润率。存在某种问题,程序仅显示一次付款的利润率。我已经在这里呆了几个小时了,尝试了Googling,但似乎找不到与我相关的特定问题。我的最后一招是在我绝对疯了之前向你们寻求帮助。该程序以葡萄牙语显示,但所有变量均以英语分配。如果您需要任何帮助理解代码,请告诉我!我试图使它尽可能地易于理解。

#Product Retail Price
product_retail_price = float(input("Valor do produto na loja em Reais (Formato 00.00): "))

#Costs
product_cost = float(input("Valor do produto no fornecedor em Reais (Formato 00.00): "))
cpa = float(input("Custo por aquisição (Formato 00.00): "))
fee_shopify = (product_retail_price / 100)*2
fee_mercadopago = (product_retail_price / 100)*4.99
fee_finance_2 = (product_retail_price / 100)*2.03
fee_finance_3 = (product_retail_price / 100)*4.06
fee_finance_4 = (product_retail_price / 100)*6.09
fee_finance_5 = (product_retail_price / 100)*7.64
fee_finance_6 = (product_retail_price / 100)*8.92
fee_finance_7 = (product_retail_price / 100)*10.06
fee_finance_8 = (product_retail_price / 100)*10.62
fee_finance_9 = (product_retail_price / 100)*11.23
fee_finance_10 = (product_retail_price / 100)*12.41
fee_finance_11 = (product_retail_price / 100)*13.60
fee_finance_12 = (product_retail_price / 100)*14.80
fee_finance_15 = (product_retail_price / 100)*18.47
fee_finance_18 = (product_retail_price / 100)*22.23
fee_finance_24 = (product_retail_price / 100)*23.83

#Calculations
parcelas = int(input("Número de parcelas sem juros (Formato: 0-24): "))
base_profit = round(product_retail_price - product_cost - fee_shopify - fee_mercadopago - cpa, 2)
profit_2 = round(base_profit - fee_finance_2 - cpa, 2)
profit_3 = round(base_profit - fee_finance_3 - cpa, 2)
profit_4 = round(base_profit - fee_finance_4 - cpa, 2)
profit_5 = round(base_profit - fee_finance_5 - cpa, 2)
profit_6 = round(base_profit - fee_finance_6 - cpa, 2)
profit_7 = round(base_profit - fee_finance_7 - cpa, 2)
profit_8 = round(base_profit - fee_finance_8 - cpa, 2)
profit_9 = round(base_profit - fee_finance_9 - cpa, 2)
profit_10 = round(base_profit - fee_finance_10 - cpa, 2)
profit_11 = round(base_profit - fee_finance_11 - cpa, 2)
profit_12 = round(base_profit - fee_finance_12 - cpa, 2)
profit_15 = round(base_profit - fee_finance_15 - cpa, 2)
profit_18 = round(base_profit - fee_finance_18 - cpa, 2)
profit_24 = round(base_profit - fee_finance_24 - cpa, 2)

#Print Values
print("\n")

if parcelas == 0 or 1:
    print(f"Lucro à vista: R${base_profit}")
elif parcelas == 2:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
elif parcelas == 3:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
elif parcelas == 4:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
elif parcelas == 5:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
elif parcelas == 6:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
elif parcelas == 7:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
elif parcelas == 8:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
elif parcelas == 9:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
    print(f"Lucro parcelado 9x: R${profit_9}")
elif parcelas == 10:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
    print(f"Lucro parcelado 9x: R${profit_9}")
    print(f"Lucro parcelado 10x: R${profit_10}")
elif parcelas == 11:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
    print(f"Lucro parcelado 9x: R${profit_9}")
    print(f"Lucro parcelado 10x: R${profit_10}")
    print(f"Lucro parcelado 11x: R${profit_11}")
elif parcelas == 12 or 13 or 14:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
    print(f"Lucro parcelado 9x: R${profit_9}")
    print(f"Lucro parcelado 10x: R${profit_10}")
    print(f"Lucro parcelado 11x: R${profit_11}")
    print(f"Lucro parcelado 12x: R${profit_12}")
elif parcelas == 15 or 18 or 17:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
    print(f"Lucro parcelado 9x: R${profit_9}")
    print(f"Lucro parcelado 10x: R${profit_10}")
    print(f"Lucro parcelado 11x: R${profit_11}")
    print(f"Lucro parcelado 12x: R${profit_12}")
    print(f"Lucro parcelado 15x: R${profit_15}")
elif parcelas == 18 or 19 or 20 or 21 or 22 or 23:
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
    print(f"Lucro parcelado 9x: R${profit_9}")
    print(f"Lucro parcelado 10x: R${profit_10}")
    print(f"Lucro parcelado 11x: R${profit_11}")
    print(f"Lucro parcelado 12x: R${profit_12}")
    print(f"Lucro parcelado 15x: R${profit_15}")
    print(f"Lucro parcelado 18x: R${profit_18}")
else: 
    print(f"Lucro à vista: R${base_profit}")
    print(f"Lucro parcelado 2x: R${profit_2}")
    print(f"Lucro parcelado 3x: R${profit_3}")
    print(f"Lucro parcelado 4x: R${profit_4}")
    print(f"Lucro parcelado 5x: R${profit_5}")
    print(f"Lucro parcelado 6x: R${profit_6}")
    print(f"Lucro parcelado 7x: R${profit_7}")
    print(f"Lucro parcelado 8x: R${profit_8}")
    print(f"Lucro parcelado 9x: R${profit_9}")
    print(f"Lucro parcelado 10x: R${profit_10}")
    print(f"Lucro parcelado 11x: R${profit_11}")
    print(f"Lucro parcelado 12x: R${profit_12}")
    print(f"Lucro parcelado 15x: R${profit_15}")
    print(f"Lucro parcelado 18x: R${profit_18}")
    print(f"Lucro parcelado 24x: R${profit_24}")
print("\n")
print("AVISO: Lucro calculado usando as taxas atuais do MercadoPago (23/07/2018)")

3 个答案:

答案 0 :(得分:2)

语句

elif parcelas == 15 or 18 or 17:

不起作用。您需要执行以下操作:

elif parcelas == 15 or parcelas == 18 or parcelas == 17:

答案 1 :(得分:1)

您可以考虑

elif parcelas == 12 or 13 or 14:

elif parcelas in [12,13,14]:

由于parcelas == 12 or 13 or 14:始终返回True,因此其求值方式类似于parcelas==121314,这绝对是True,而忽略以下语句。

为打印语句创建列表:

>>> lst=[]
>>> for i in range(2,24):
        lst.append("Lucro parcelado "+str(i)+"x: R${profit_"+str(i)+"}")


>>> lst
['Lucro parcelado 2x: R${profit_2}', 'Lucro parcelado 3x: R${profit_3}', 'Lucro parcelado 4x: R${profit_4}', 'Lucro parcelado 5x: R${profit_5}', 'Lucro parcelado 6x: R${profit_6}', 'Lucro parcelado 7x: R${profit_7}', 'Lucro parcelado 8x: R${profit_8}', 'Lucro parcelado 9x: R${profit_9}', 'Lucro parcelado 10x: R${profit_10}', 'Lucro parcelado 11x: R${profit_11}', 'Lucro parcelado 12x: R${profit_12}', 'Lucro parcelado 13x: R${profit_13}', 'Lucro parcelado 14x: R${profit_14}', 'Lucro parcelado 15x: R${profit_15}', 'Lucro parcelado 16x: R${profit_16}', 'Lucro parcelado 17x: R${profit_17}', 'Lucro parcelado 18x: R${profit_18}', 'Lucro parcelado 19x: R${profit_19}', 'Lucro parcelado 20x: R${profit_20}', 'Lucro parcelado 21x: R${profit_21}', 'Lucro parcelado 22x: R${profit_22}', 'Lucro parcelado 23x: R${profit_23}']
>>> 

答案 2 :(得分:0)

在线

if parcelas == 0 or 1:

正在评估parcelas == 01的两个独立条件。因为1将被评估为true,所以将始终输入此语句。您需要确保与每个想要比较的值进行比较-parcelas == 0 or parcelas == 1

还有其他类似问题的行。

还有其他更整洁的方式编写此代码,但是我对python不够熟悉,无法了解这些语法。如果您只关心范围,而不是离散值列表,请考虑对这些条件使用类似parcelas >= 0 and parcelas < 2的方法。