+ 2

Super sale

Hello guys, This is my code for the Super Sale problem, some of the output are correct but not all and I don’t know why: import math price = input() price_list = price.split(',') price_list_int = [int(x) for x in price_list] highest = 0 for i in price_list_int: if i >= highest: highest = i price_list_int.remove(i) save = 0.3*sum(price_list_int) new_price = sum(price_list_int)-save taxe = 0.07 * save total_save = math.floor(save+taxe) print(total_save) Thanks !

12th Apr 2023, 1:04 PM
Julien Badii
2 Answers
+ 9
Julien Badii , there are 2 issues in thd code: (1) the list comprehension used is converting the prices to an integer value, so all decimal places get eliminated: ... price_list_int = [int(x) for x in price_list] # should be float(x) not int(x) ... (2) the code in the for loop does not necessarily create correct results, since values are removed during iteration cycles: ... for i in price_list_int: # do not iterate over a list where elements are removed !!!! if i >= highest: highest = i price_list_int.remove(i) ... to get the highest price removed, we can use max(...) function and remove this from *price_list_int* >> after applying this modifications, the code should pass all test cases properly.
12th Apr 2023, 5:18 PM
Lothar
Lothar - avatar
+ 3
Is it that you need to floor or round up?
12th Apr 2023, 1:47 PM
Ausgrindtube
Ausgrindtube - avatar