Only to complement the another answer:
In the elif
no need to test whether PRODUTO >= LIMITE * 0.6
.
If you didn’t get into the if PRODUTO < LIMITE * 0.60
, is because the product is not less than LIMITE * 0.60
. So we arrived at the elif
is because it is certainly greater or equal. Then just test the other condition:
limite = 1000
produto = 901
if produto < limite * 0.6:
print('valor menor que 60%')
elif produto <= limite * 0.9:
print('entre 60% e 90')
elif produto <= limite:
print('entre 90% e 100%')
That is, if it is less than 60%, it enters the if
.
If you didn’t get into the if
, is because it is greater than or equal to 60%. Then elif
just test if it is less than or equal to 90%. Test again if it is >= limite * 0.6
is redundant and unnecessary.
I also included a test to see if it’s between 90% and 100%, which seems to be a requirement. It has not been defined what to do if the value is greater than 100% of the limit, or if it is negative, but if it were, it would be enough to add new conditions. Ex:
if produto < 0:
print('valor não pode ser negativo')
elif produto < limite * 0.6:
print('valor menor que 60%')
elif produto <= limite * 0.9:
print('entre 60% e 90')
elif produto <= limite:
print('entre 90% e 100%')
else:
print('valor maior que o limite')
The idea is the same: if it is less than zero it enters the if
. If you don’t go in there, it’s because it’s definitely greater than or equal to zero, then in the first elif
I only test if it’s less than 60%. And so on...
Also note that I wrote the numbers as 0.6
and 0.9
. How they are numerical literals, the extra zeroes (0.60
and 0.90
) make no difference.
And I used the variable names with lower case letters, following the PEP 8 conventions.
"I’m not going to quote my code here because I might get the answer on a silver platter" - It’s actually the opposite: when you don’t put any code, gives the impression that you have done nothing and want us to do everything for you (even if it is not that, it is the impression that passes). The ideal is to put what you’ve tried and explain why it didn’t work - which is what we call [mcve]
– hkotsubo
ah... beauty did not know. It’s for a college exercise and I didn’t want to have an answer with all the calculations already done and so on... but I’ve done all the rest of the code yes, just missed this calculation. Thank you for clarifying, I will improve in the next!
– Felipe