2
I am a beginner in the world of programming and also in python.
Solving some exercises I came across this
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-litre cans; buy only 3.6 litre 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.
My resolution works, I arrive at the expected result, but the logic I used is very extensive. how could it resolve this issue more efficiently? follows below the code. Thanks in advance.
import math
m2 = float(input('informe a quantidade de METRO QUADRADO (m²) a ser pintado: '))
consumo_litro = m2 / 6
print('\no consumo de tinta é: {:.2f} LITROS\n'.format(consumo_litro))
qtd_latas18 = consumo_litro / 18
qtd_latas36 = consumo_litro / 3.6
print('a quantidade de GALOES de 18 LITROS a ser usado é: {}'.format(math.ceil(qtd_latas18)))
print('a quantidade de LATAS de 3,6 LITROS a ser usado é: {}\n'.format(math.ceil(qtd_latas36)))
valor_total18 = math.ceil(qtd_latas18) * 80
valor_total36 = math.ceil(qtd_latas36) * 25
print('o valor total em GALOES de 18 LITROS é: R${}'.format(valor_total18))
print('o valor total em LATAS de 3,6 LITROS é: R$ {}\n'.format(valor_total36))
print('considerando o menor desperdíciode tinta, temos: \n')
qtd_latas_mistas18 = ((consumo_litro * 0.10) + consumo_litro) / 18
qtd_litros18 = math.trunc(qtd_latas_mistas18) * 18
resto18 = ((consumo_litro * 0.10) + consumo_litro) - qtd_litros18
qtd_latas_mistas36 = resto18 / 3.6
qtd_latas_mistas_total = math.trunc(qtd_latas_mistas18) + math.ceil(qtd_latas_mistas36)
valor_misto18 = math.trunc(qtd_latas_mistas18) * 80
valor_misto36 = math.ceil(qtd_latas_mistas36) * 25
total_misto = valor_misto18 + valor_misto36
print('quantidade de latas de 18 litros: {}'.format(math.trunc(qtd_latas_mistas18)))
print('qtd latas de 3,6: {}'.format(math.ceil(qtd_latas_mistas36)))
print('qtd latas mistas: {}'.format(qtd_latas_mistas_total))
print('\no valor total considerando GALOES e LATAS é (acresentando 10% de quebra): R$ {}'.format(total_misto))
One mistake I noticed is that you consider the 10% off only for the calculation of mixed cans when you should consider for all situations. To facilitate consider the area to be painted plus 10%. An operator that would facilitate its calculation in the mixed option is the rest of the division (%). It could eliminate some intermediate variables but with the time of programming practice will identify these situations.
– anonimo
your code is not bad, it is well written the names of the variables, but the good is you do not put all it, since it is work of the college, comes another and copies your work and still runs the risk of your teacher find your code here.
– Marco Souza
Another thing: A tin can has 18 l and the gallon 3.6 l. In printing you write backwards.
– anonimo
thanks for all your help. @Marco Souza is actually not going to college. I decided to learn programming and am performing some exercises of the internet
– Renan Schuck
For the sake of organization, it would be good to separate the code into functions, simplifying the parts, this will also help to reuse some of these parts
– Costamilam