+ 2

Ballpark orders test 5

I try to find solution here but nothing help. Error in the test 5. What should I correct in my code? https://sololearn.com/compiler-playground/clIhFj255vQw/?ref=app P. S. I hope the link correctly. If not: order = input() words = len(order.split()) six = order.count('Nachos') + order.count('Pizza') ten = order.count('Cheeseburger') four = order.count('Water') five = order.count('Coke') all_menu = six + ten + four + five another = words - all_menu all_price = round(1.07 * (6*six + 10*ten + 4*four + 5*(five + another)),2) print(all_price)

21st Dec 2023, 8:38 AM
Андрей Мальков
Андрей Мальков - avatar
41 ответ
+ 7
Solo , you are absolutely right. you did a great job. > the key issue is, that .count() using strings as input, also detect the search word if it is a substring.
23rd Dec 2023, 10:49 AM
Lothar
Lothar - avatar
+ 5
Rain Exactly! I completely forgot about this moment! I’ll make a note to deal with it so I can definitely fix it. Thank you very much everyone for participating! It was an interesting experience in analyzing the problem.
22nd Dec 2023, 1:49 PM
Андрей Мальков
Андрей Мальков - avatar
+ 4
Personally, I wouldn't bother with this challenge because I think the main problem is the design of the challenge and not the code. Unfortunately, SL has not yet commented on this.
22nd Dec 2023, 11:09 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Okay, I checked my code. *1.07 gives me also failed cases. After summing up all prices: print(sum + (sum*0.07))
21st Dec 2023, 10:34 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Tbh I have no clue why your code fails. Here is mine: dic = {"Nachos":6, "Pizza":6, "Cheeseburger":10, "Water":4, "Coke":5} order = input() order_list = order.split() sum = 0; for i in order_list: if i in dic: sum += dic[i] else: sum += 5 print(sum + (sum*0.07))
21st Dec 2023, 10:46 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
I found a way to get the order list for test case 5: I checked for each index of the order list if it is Nachos or whatever and printed something, otherwise I printed the correct output. So I just needed to check when I got a fail for testcase 5. Input: Water, Water, Pizza, Unknown Output: 20.33 Now I have really no clue why your code fails because you print 20.33 Maybe it's time for a bug report.
21st Dec 2023, 5:15 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Андрей Мальков If you want, you can write SL an email and explain your problem to them again: info@sololearn.com I have also reported the problem myself. However, I'm afraid that it's not a priority at the moment because other developments need to be pushed forward.
22nd Dec 2023, 11:45 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Андрей Мальков , Solo already wrote the fix. You only have to change the first two lines. I tried it in the Code Coach, and it passed all test cases, but I didn't save and link it, because he should, since it's his. Test case 5 is likely missing a space between two of the items in the input string, making most people's code see it as a single unknown item, but your code saw it as two known items.
22nd Dec 2023, 1:09 PM
Rain
Rain - avatar
+ 2
Maybe the round function gives you an error. And as far as I know you don't need to round. all_price = 1,07*(....) should be enough.
21st Dec 2023, 10:22 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Андрей Мальков , I understand your code too, but I can't figure out why it's failing a hidden test case. This is the first time I can't debug something here. Weird. I copied it to Pydroid 3, added a bunch of print statements to see all the variable states, and tried a bunch of combinations. The resulting price always looked right. Here's the Code Coach link for anyone wanting to read the description. Ballpark Orders https://www.sololearn.com/coach/15?ref=app
21st Dec 2023, 12:48 PM
Rain
Rain - avatar
+ 2
Андрей Мальков , I crammed yours and mine together and fed them every food combination in a dual test, and they agree on every price, yet yours fails Test Case 5. WTF? I wish it weren't hidden. Maybe the input string is malformed or something weird. https://sololearn.com/compiler-playground/c83cW1dA5VEV/?ref=app
21st Dec 2023, 4:19 PM
Rain
Rain - avatar
+ 2
split(" ") splits exactly by one space split() by any number of spaces The difference can be seen at this code: order = "Water Coke Cheese Bread" print (order) print(order.split()) print(order.split(" ")) If there is only one space, and according to the condition it is, then there is no difference. Your code is correct.
21st Dec 2023, 6:37 PM
wind--1699
+ 2
Solo , You can share your code by hitting the share icon in the playground and hitting Copy, which puts the link in the clip to be pasted anywhere (such as a comment here) until you overwrite the clip with another Copy. Your fix passes Test Case 5, which suggests the input string is missing a space. If I, a human, read "Nachos Nachos NachosNachos" (for example) and I knew that four people were eating, I'd bring back four orders of Nachos, not two and a Coke, meaning that the code that counts occurrences of the substring is actually more robust in human terms. If the correct answer for Test Case 5 assumes that the code should be entirely literal and turn NachosNachos into Coke, which is why most other code solutions pass, that violates the description that implies there must be four items (you and three friends), not three. Or the input is like "Name Name Name NameName", so 4 items but 5 valid substrings. Either way, TC5 is funky.
22nd Dec 2023, 12:30 AM
Rain
Rain - avatar
+ 2
Rain Thank you for the explanation about adding the link. However, I haven't figured it out yet, I don't have time now. I'll definitely do it later. Regarding the correctness or incorrectness of the task. Not just missing spaces... Well... Here's another example. One of your friends wants a watermelon. And this code will order water for him. And he doesn't want water. He loves rum and coke. And if you order him a coke instead of a watermelon, which is not on the menu, he will not be offended.
22nd Dec 2023, 3:01 AM
wind--1699
+ 2
Андрей Мальков And thank you. You've come up with an interesting side challenge.
22nd Dec 2023, 3:06 AM
wind--1699
+ 2
Denise Roßberg I was sure that I didn’t understand something as a newbie. But seeing that even more experienced comrades cannot so easily understand what the catch is, of course I will go further. I'm glad that my code still works, although there is a bug hidden somewhere. Will SL comment on it himself or should I write to them somewhere?
22nd Dec 2023, 11:39 AM
Андрей Мальков
Андрей Мальков - avatar
+ 2
Rain Yes, I now found a difference when I use WaterCheeseburger as input.
22nd Dec 2023, 1:22 PM
Jan
Jan - avatar
+ 2
Андрей Мальков , I like the "what's wrong with my code" type discussions because it's good practice in reading code. It's one level to read working code and understand it, but it's a little higher level to read broken code and understand it. IMO, you code wasn't really broken. It turned out more to be a difference in design that only became apparent in response to malformed input. Kudos to Solo for realizing the difference. The third level is figuring out when the test itself might be wrong! This one also gave me the first reason I ever had to take two separate programs, turn them into functions in the same program, send them the same exhaustive (well-formed, which is why it didn't find the difference) input using itertools.combinations_with_replacement (first time I've ever used that too), and compare their output.
22nd Dec 2023, 9:21 PM
Rain
Rain - avatar
+ 1
Denise Roßberg no. Without round function tests 3 and 4 failed
21st Dec 2023, 10:27 AM
Андрей Мальков
Андрей Мальков - avatar
+ 1
Nothing is changes. Test 5 don't give up
21st Dec 2023, 10:40 AM
Андрей Мальков
Андрей Мальков - avatar