How to solve the BallPark Order Challange ? | Sololearn: Learn to code for FREE!

0

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

tag

12/23/2019 4:14:02 PM

Roberto M

15 Answers

New Answer

+3

Thank 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,

+3

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))

+1

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.

+1

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()

+1

How do I convert that list [] populated by strings to int(numbers) ?

+1

Yes, include "Nachos"

+1

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

+1

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 😉

+1

bit of tip, try using a for loop instead to avoid repeating codes

0

It's "Cheeseburger" and you missed the case for "Nachos"

0

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.

0

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 ?

0

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?

0

Yes ['Coke', 'Nachos', 'Coke']

0

You're welcome