+ 2

Code Coach: Duty Free - Python

I pass everything except test case 6. Any ideas what could be wrong with my existing code? items = (input()) items_list = items.split(" ") float_list = [float(x) for x in items_list] total = sum(float_list) * 1.1 if total > 20: print("Back to the store") else: print("On to the terminal")

9th Apr 2025, 1:27 AM
Rance Pratt
Rance Pratt - avatar
5 Answers
+ 4
iirc you have to check the price for each item so if conversion > 20 then end else reloop
9th Apr 2025, 1:31 AM
ć€Œļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ 3O ļ¼Øļ¼„ļ¼¬ļ¼°ć€
ć€Œļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ 3O ļ¼Øļ¼„ļ¼¬ļ¼°ć€ - avatar
+ 4
Rance Pratt , as already mentioned, we have to check each *individual item* if it exceeds 20. this can be done by slightly reworking the logic of the code: ... # instead of multiplying the *sum of the float_list* by 1.1 we can do this step here. this multiplies each individual value: float_list = [float(x) * 1.1 for x in items_list] # next line is not required: # total = sum(float_list) * 1.1 # to check if any item exceeds 20, we can just use the *max()* function with the *float_list*: if max(float_list) > 20: ... after this modifications the task should run properly.
9th Apr 2025, 8:18 AM
Lothar
Lothar - avatar
+ 3
Rance Pratt you need to read the instructions carefully .... You make a purchase of souvenirs priced in Euros at a duty free store in the Rome airport. You didn't want to spend any more than 20 US Dollars on any specific item. Can you go through your list and make sure you stayed under your limit? The conversion rate on this day is 1.1 US Dollars to 1 Euro. Task: Evaluate each item that you purchased to make sure that you didn't spend more than $20 on that particular item. If you did, you will need to go back to the store to return it. Input Format: An string of numbers separated by spaces that represent the prices of each of your items in Euros. Output Format: A string that says 'On to the terminal' if you stayed under your cap, or 'Back to the store' if you spent too much money. Sample Input: 18 15.50 2 14 Sample Output: On to the terminal Explanation: You stayed under your cap because your most expensive item only cost $19.80 in US dollars (1 Euro = 1.1 USD).
9th Apr 2025, 2:24 AM
BroFar
BroFar - avatar
+ 3
NWANEBIKE CHISOM DANIEL , sorry to say, but the provided code sample does not pass all test cases. the code checks the *sum of all items*, but should check each *individual item* against the required condition.
11th Apr 2025, 7:47 AM
Lothar
Lothar - avatar
+ 1
items = input() items_list = items.split(" ") float_list = [] for x in items_list: try: float_list.append(float(x)) except ValueError: pass if float_list: total = sum(float_list) * 1.1 if total > 20: print("Back to the store") else: print("On to the terminal") else: print("Invalid input") Try this
10th Apr 2025, 10:07 PM
NWANEBIKE CHISOM DANIEL