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

While trying to solve above mentioned code coach problem (ref--https://www.sololearn.com/coach/58?ref=app) I wrote this following code. prices = input().split(",") max = max(prices) prices.remove(max) before_sale = sum([float(i) for i in prices],float(max))*1.07 #print (before_sale) after_sale = sum([float(i) * 0.7 for i in prices],float(max))*1.07 from math import floor as f savings = f(before_sale - after_sale) print (savings ) It passes all the tests except 4th one. Can anyone help me find the bug in this code that makes it fail the 4th test. Thanks in advance!!

28th Dec 2020, 4:48 AM
CHANDAN ROY
CHANDAN ROY - avatar
2 Answers
+ 2
Hi! A problem is that you use the built in function max() on string values, before you convert the values to floats. It works, but the result probably becoms the unexpected. In the world of strings “100” < “80”, as an example. An other problem can be to name a variable max, at the same time you are using the max() function. Regards /Per B 🙂
28th Dec 2020, 8:14 AM
Per Bratthammar
Per Bratthammar - avatar
+ 1
I have finally solved the above mentioned problem. Thanks for your input sir. Here is my updated code-- list = input().split(",") prices = [] for price in list: prices.append(float(price)) maximum = max(prices) before_sale = sum([i for i in prices])*1.07 prices.remove(maximum) after_sale = sum([i * 0.7 for i in prices],maximum)*1.07 from math import floor as f savings = f(before_sale - after_sale) print (savings)
28th Dec 2020, 8:57 AM
CHANDAN ROY
CHANDAN ROY - avatar