0

I cant pass the 4th test on this challenge

Hi, my code is failing on the 4th test of the super sale challenge. And I have no idea why, can someone please help me 😊 Your favorite store is having a sale! You pay full price for the most expensive item that you get, but then you get 30% off of everything else in your purchase! How much are you going to save? Sales tax is 7%. Also, you leave anything below a dollar in your saving as a tip to the seller. If your saving is a round amount, you don't leave any tips. Task: Given the prices of items you want to purchase, determine how much you will save during your shopping! Input Format: An string of numbers separated by commas that represent the prices for all of the items that you want to purchase (without tax). My code is: from math import floor as floor i = input().split(",") m = float(max(i)) sum = 0 for x in i: if float(x) == m: continue else: sum += float(x) print(floor((sum * 0.3) * 1.07))

8th Jul 2022, 7:35 AM
Martin Valdés Mallaug
2 RĂ©ponses
+ 3
Martin Mallaug Your math solution won't meet all requirements. Lets look at an example. input -> 15,9,6,7,8 total before reduction 45 45 * 7%tax = 3.15 9+6+7+8 = 30 30 * 30% = 9 saved But your tax is now reduced also 15 + 21 = 36 * 7% = 2.52 3.15 original tax - 2.52 adjusted tax = another saving of 0.63 total saving = 9 + 0.63 = 9.63 Then you round out the savings As you can see, the requirements are very different to your code
8th Jul 2022, 8:43 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Another issue is that your code skips all items with maximum price - none is included in the sum. One suggestion is to create two functions: one to choose the full priced item, and another to calculate savings on each item. Then add sales taxes in the end. It can make your code better organized, and easier to implement each requirement.
8th Jul 2022, 3:35 PM
Emerson Prado
Emerson Prado - avatar