0

SuperSale Challenge

How do i fix this why is TestCase #3,4 and 7 is wrong cost = input().split(",") cost = [float(x) for x in cost] cost.remove(max(cost)) tax = int(sum(cost) * 0.07) discount = 0 for i in cost: discount = float(discount)+ (i * 0.3) savings = tax + discount print(int(savings))

24th May 2023, 6:06 AM
Adventure of Tol
Adventure of Tol - avatar
5 Réponses
+ 6
Adventure of Tol , we can simplify the code and also get it run: cost = input().split(",") # next 3 lines are your code cost = [float(x) for x in cost] cost.remove(max(cost)) total_discount = sum(cost) * 1.07 * 0.3 # rework this line -> build the sum of cost, add the tax and calculate the saving #discount = 0 # next 4 lines are not required #for i in cost: # discount = float(discount)+ (i * 0.3) #savings = discount print(int(total_discount)) # output the result
24th May 2023, 10:02 AM
Lothar
Lothar - avatar
+ 7
Adventure of Tol , this way (multiplying by 1.07) we add the required tax of 7% to the sum of the cost. after this step we calculate the discount by multiplying by 0.3.
24th May 2023, 3:18 PM
Lothar
Lothar - avatar
+ 4
Where is task description? Add details pls.. edit: Adventure of Tol Don't round the tax before. round only total savings...
24th May 2023, 8:44 AM
Jayakrishna 🇮🇳
+ 1
Lothar Thanks brother, but can you enlighten me why the sum(cost) is multiplied to 1.07?
24th May 2023, 1:26 PM
Adventure of Tol
Adventure of Tol - avatar
0
Jayakrishna 🇮🇳 I have tried this already and the result is only test case 6 is right
24th May 2023, 1:20 PM
Adventure of Tol
Adventure of Tol - avatar