Problem with 'Kaleidoscopes' code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

21st Dec 2022, 3:46 PM
Yousha
Yousha - avatar
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.
21st Dec 2022, 4:35 PM
Lothar
Lothar - avatar
+ 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
21st Dec 2022, 7:06 PM
Lothar
Lothar - avatar
+ 2
Lothar , It seems statistics is not my strong suit. I'll work on that. Thank you for the help.
21st Dec 2022, 6:27 PM
Yousha
Yousha - avatar
+ 2
Lothar , Thank you. It is working now
22nd Dec 2022, 8:16 AM
Yousha
Yousha - avatar