Doubt in Python Exercise Logic (Beginner)

Asked

Viewed 92 times

0

Hello, I recently started my study in Python Programming Logic. I have a small base in C. I came across an exercise on the Internet where it says the following:

"Make a Program for a paint shop. The program should ask for the size in square meters of the area to be painted. Consider that the paint cover is 1 liter for every 6 square meters and that the paint is sold in 18 liter cans, which cost R $ 80,00 or 3,6 liter gallons, which cost R $ 25,00. Inform the user the quantities of ink to be purchased and the respective prices in 3 situations:

  • buy only 18 liter cans;
  • buy only 3.6 liter gallons;
  • mix cans and gallons so that the waste of paint is less. Add 10% off and always round up the values, that is, consider full cans."

The problem is that I arrived in the third scenario and could not develop the right thinking of how I should do to calculate the form of higher cost x benefit. Could someone give a hint and let me know if the logic I’m following is correct ?

Code:

metros = float(input("Informe os m²: "))
litros = metros/6
if(metros%108 > 0 and metros%21.6>0): 
latas = metros//108
latas = latas + 1
preçol = latas * 80
galao = metros//21.6
galao = galao + 1
preçog = galao * 25
print("Você vai precisar de: {} latas de 18L e vai gastar {} reais".format(latas,preçol))
else:
latas = metros/108
preçol = latas * 80
galao = metros/21.6
preçog = galao * 25
print("Você vai precisar apenas de {} latas de 18L e vai gastar {} reais".format(latas,preçol))
print("Você vai precisar apenas de {} galao de 3,6L e vai gastar {} reais".format(galao,preçog))

1 answer

0

I hit my head to solve this problem. But I managed to solve

At first, I performed the calculation function, where I declare some base variables such as the price and size of cans/roosters.

After that, I declared another variable to receive the value of the total liter passed by the user, divided by the size of the cans/ roosters to have the value of maximum cans will be necessary and with an added condition, if the value is different from 0 ( ie, the amount of cans and less than what is needed), where this result of the rest of the division (%) and made with the roosters of 3.6L.

follows below the code:

def calculo_loja_tintas(litro):
    # LATAS
    latas = litro / 18
    if latas % 18 != 0:
        latas += 1
    preco_das_latas= latas * 80

    # GALOES
    galoes = litro / 3.6
    if galoes % 3.6 != 0:
        galoes += 1
    preco_dos_galoes = galoes * 25

    mistura_lata = int(litro / 18.0)
    mistura_galao = int((litro - (mistura_lata * 18)) / 3.6)
    if litro - (mistura_lata * 18) % 3.6 != 0:
        mistura_galao += 1
    galoes_total = (mistura_lata * 80) + (mistura_galao * 25)


    print(f'''
        Total de Litros necessário para pintar: {litro:.0f}L
        Apenas latas de 18 litros: {latas:.0f} Und. - Preço: R$ {preco_das_latas:.2f}
        Apenas galões de 3.6 litros: {galoes:.0f} Und. - Preço: R$ {preco_dos_galoes:.2f}
        Mistura: {mistura_lata:.0f} Latas e {mistura_galao:.0f} Galões = 
        R$ {galoes_total:.2f}''')

area_pintura = float(input('Tamanho em metros quadrados da área a ser pintada: '))
litros = area_pintura / 6  * 1.1
calculo_loja_tintas(litros)

I like to declare variables complete, for better reading. I am not very good at explaining many things, but if in case you still have any doubts about, comments there that I try to help you dnv.

Thank you and good studies.

@Edit: There is a question with the same problem, if you want another way to solve the exercise: Click Here to be directed to the post

Browser other questions tagged

You are not signed in. Login or sign up in order to post.