Super Sale Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Super Sale Problem

QUESTION PROMPT: 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. I CAN SOLVE 6/7 TEST CASES (FAILING TEST CASE 4). WHATS WRONG? https://code.sololearn.com/cemz9c964iGD/?ref=app

12th May 2020, 7:24 PM
Tyrhen Williams
Tyrhen Williams - avatar
5 Answers
+ 6
Having looked again at your code, I realised the problem could be in your finding of the orice of the most expensive item. You don't change the prices to ints until after you find the p_max, so you've only compared the strings of the prices. That means that if you had an item at "12" and another at "5", it would take "5" to be the greater price. Also, you may run into problems if there are two items with equal maximum price as I think you would still get 30% of the second maximum-priced item.
12th May 2020, 9:59 PM
Russ
Russ - avatar
+ 4
items = sorted(list(map(float, input().split(",")))) taxed = [i * 1.07 for i in items] discounted = [i *.3 for i in taxed[:-1]] savings = int(sum(discounted)//1) print(savings)
25th Oct 2021, 5:48 AM
Mateo González Bufi
Mateo González Bufi - avatar
+ 3
I realized I should of been converting the string to a float not an integer! that was messing up the calculations. thanks for the help
13th May 2020, 1:58 AM
Tyrhen Williams
Tyrhen Williams - avatar
+ 2
Try changing print(math.floor(total*1.07)) to print(round(total*1.07, 2)). I'm sure it's just a rounding error.
12th May 2020, 9:36 PM
Russ
Russ - avatar
0
x = input().split(',') n = 0 for i in x: x[n] = float(i) n+=1 x = sorted(x) x.pop() f = sum(x)*0.3 final = f + (f*0.07) print(int(final)) I was only successful ‘til test#3 at first. My previous code was specific: (x[0] + x[1]) instead of sum(x). I don’t know what was wrong since test#4 onwards is locked. I just tried to change it instead to sum(x) and it passed all. But I still hope to see them all, to figure out what was wrong.
8th Apr 2023, 4:38 PM