+ 1
Ballpark Orders in Code Coach failing some tests
So my solution for the Ballpark Orders code coach problem is failing some tests which I can't tell because they're locked. https://code.sololearn.com/c516cMrC9B98/?ref=app
9 odpowiedzi
+ 1
According to the task description, we should round the result to 2 decimal places. Could that be the reason?
+ 2
If I enter "Do", I get "_do" as output. I think it should be "do".
+ 2
I chose the "lazy" approach and first split the input at uppercase letters with the help of regular expressions and stackoverflow. Then I made all elements of the list lowercase and used join() with "_"
+ 1
Your code gives an error when you enter a meal that is not available. Test "Fries Water" for instance.
+ 1
The tests are hidden _because_ it would be to easy otherwise. ;)
If we knew the test cases, we could "cheat" and hard-code the output. Keeping some test cases hidden, forces us to focus on the task requirements and the logic.
You might be interested in the dictionary method get() which can help you to handle cases in which the queried key does not exist in the dictionary.
0
Lisa Thank you. I've edited the code because I got the name of the dictionary wrong (orders instead of menu) in the list comprehension, but it still doesn't pass those tests.
total_price = sum([menu[snack] if snack in menu else menu['coke'] for snack in orders]) * 1.07
0
Lisa Thank you, that worked. It was so frustrating especially seeing as it was marked "easy". Do you have any idea why some tests are hidden? Life would be so much easier if we could see why the tests are failing.
0
Could you please look at this one and find out why it's failing the last test? It's supposed to convert the input which is in camel case to snake case. Thanks Lisa
https://code.sololearn.com/cBy8hzO4W8Vq/?ref=app
0
Thank you! Lisa
I managed to tweak it and while it looks ugly, it works. I would be interested to see your own implementation of a solution to this problem, when you have the time, of course. I know there are far better solutions than mine.
I also hope to learn how to test my code. I guess it's a skill that comes with practice because those hidden tests really trip me up and I'm never really sure how to test the code. Thank you again.