skip to Main Content

I’m new here at StackOverflow but I’ve been “messing around with” HTML and CSS since the age of 8. I recently picked up a course on Python (at 25) and decided to use programming as an expansion of my career path. I’m working on a small program that allows me and fellow Shopify eCommerce owners (in Brazil where I currently live) to calculate the profit margin of a single product, using user input (product retail price, product cost, cpa) . It’s also supposed to display the profit margins depending on the amount of times a store/vendor finances the product without interest (parcelas). There is some kind of issue where the program only ever displays the profit margin for a 1 time payment. I’ve been at this for hours and tried Googling but can’t seem to find a specific issue that would tie in with mine. My last resort is to ask you guys for help before I go absolutely insane lool. The program displays in portuguese but all the variables are assigned in English. If you need any help comprehending the code, please do let me know! I have tried to make it as comprehensible as possible.

#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

Answers


  1. statements like

    elif parcelas == 15 or 18 or 17:
    

    will not work. You need to do something like:

    elif parcelas == 15 or parcelas == 18 or parcelas == 17:
    
    Login or Signup to reply.
  2. In the line

    if parcelas == 0 or 1:
    

    There are two separate conditions being evaluated parcelas == 0, and 1. Because 1 will be evaluated as true, this statement will always be entered. You need to ensure to compare with every value you want to – parcelas == 0 or parcelas == 1

    There are other lines with similar issues.

    There are other ways to write this that will be neater, but I’m not familiar enough with python to know the syntax for those. If you just care about a range, rather than a list of discrete values, then consider using something like parcelas >= 0 and parcelas < 2 for these conditions.

    Login or Signup to reply.
  3. You can consider make

    elif parcelas == 12 or 13 or 14:
    

    to

    elif parcelas in [12,13,14]:
    

    and etc.

    Because parcelas == 12 or 13 or 14: will always return True, it will evaluate like parcelas==12 or 13 or 14, which is definitely True and ignore the following statement.

    Create list for print statement:

    >>> 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}']
    >>> 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search