+ 2
Problem with 'Kaleidoscopes' code
I think my formulas could be off (i am feeling brain fogged), but the required output value does not match the value outputted by my code (we are supposed to add a 10% discount to the total amount if someone has bought more than 1 kaleidoscope, and 7% tax on the total applies on either case): quantity = int(input()) amount = quantity*5.00 tax = (7/100)*amount discount = (10/100)*amount if quantity > 1: print(amount - discount + tax) else: print(amount + tax) Please let me know what is wrong. Thank you.
4 Answers
+ 5
Yousha ,
there are 2 issues to solve:
> all outputs has to be with 2 decimal places. (see task description)
> for all purchases with a quantity > 1, the tax calculation is not correct. calculate the tax *after* the discount is subtracted.
+ 3
Yousha ,
may be it is easier to handle the calculation of tax and discount by using a factor instead of formulas.
pre-calculate these factors and then use them.
> the reduction of the discount has a factor of 0.9 = ((-10 + 100) / 100)
> the calculation of the tax has a factor of 1.07 = ((+7 + 100) /100)
if quantity is > 1: amount * factor_discount * factor_tax => and output it to 2 decimal places
if quantity is 1 : amount * factor_tax => and output it to 2 decimal places
+ 2
Lothar ,
It seems statistics is not my strong suit. I'll work on that. Thank you for the help.
+ 2
Lothar ,
Thank you. It is working now