How to solve the BallPark Order Challange ?
I managed to solve the BallPark Order challenge on my PC yet here in SoloLearn app does not pass the test cases! Any help how could I do it would be appreciated! My code it attached! https://code.sololearn.com/cNQgbgtWhP4m/?ref=app
12/23/2019 4:14:02 PM
Roberto M
15 Answers
New AnswerThank You very much Thomas! Funny, I wrote the exact same code 1h ago and I delete it as it would print the prices separately and not as a total. Now I realised it was because I did not indent Print () function properly. Regards,
order = input() #'Mierda Mierda Mierda Mierda' #input() list_ord = {'Nachos': 6, 'Pizza': 6, 'Cheeseburger': 10, 'Water': 4, 'Coke': 5} productos = ['Nachos', 'Pizza', 'Cheeseburger', 'Water', 'Coke'] suma = 0 new_ord = order.split(" ") for i in new_ord: if (i in productos) == True: suma += list_ord.get(i) else: suma += list_ord.get('Coke') print(round(suma*1.07, 2))
Sometimes, the input string have an \r at the end. Try adding .strip() to your input (likely the last) and see if that solves the problem.
You will get the input as one String. In the task descriped as: Input Format You are given a string of the four items that you've been asked to order that are separated by spaces. So you can't get it item by item. Put the whole order in a list. Like this: order = input(). split()
Fine Delete the print Now we make a loop over that list: sum = 0 for i in order: if i == 'Nachos' sum += 6 elif i == 'Coke' sum += 5 . . else: sum +=5 This added All items. The last "else" is for the case, the ordered item is not to have. print(sum) #to check if it works as expected
And next month you will do that with a dict like this price = {'Nachos':6.00, 'Pizza': 6.00, 'Cheeseburger': 10.00, 'Water': 4.00, 'Coke': 5.00} It's shorter and a little bit nicer 😉
You have to read the items from the list. For exsample, if order is your list: item1 = order[0] item2 = order[1] and so on. And if you have the items, maybe go your way with the cases and prices.
I managed to solve this on my PC. I get the total for every combination of 4 items. But here in SoloLearn?! I have to do it exactly as the TEST Cases and it doesn't work. Do you have any tips as to how to solve this ?
We can do that STEP by STEP if you want. start with order = input(). split() print(order) # to See what we have. Make input in one line: Coke Nachos Coke SUBMIT Do you See the list?