+ 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!!

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 🙂

+ 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)

Hot today

What is indentations... ?

6 Votes

Application RAM usage

1 Votes

Showing errors!

2 Votes

About Java McQ

0 Votes

Q. Anna is 18 years old

-2 Votes

int num = 2;
int x = 3;
if(num >= 2) {
if(x > 4) { num = 3; }
else { num = 4; }
}
else {x = 1; }

1 Votes

Balconies Problem in C

0 Votes