+ 2
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
29 Respostas
+ 10
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))
+ 5
a=input()
a=a.split(" ")
sum=0
for i in a:
if i=="Nachos":
sum+=6
elif i=="Pizza":
sum+=6
elif i=="Cheeseburger":
sum+=10
elif i=="Water":
sum+=4
else:
sum+=5
print(round(sum*1.07,2))
+ 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,
+ 2
a=input()
b=a.split()
my_dict= {"Cheeseburger":10, "Water":4, "Coke" : 5, "Nachos": 6, "Pizza": 6}
res=0
for i in b :
if i in my_dict :
res= res+my_dict[i]
else:
res = res + my_dict["Coke"]
sonuc= float(res*1.07)
print(round(sonuc,2))
I've found that, I've missed to "round"
+ 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
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 ?
+ 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
+ 1
I think itās more beautiful to use dictionaries to solve this problem:
menu = {'Nachos': 6,
'Pizza': 6,
'Cheeseburger': 10,
'Water': 4,
'Coke': 5}
order=input()
total = 0
ord= order.split()
for i in ord:
if i in menu:
total += menu[i]
else:
total += menu["Coke"]
print(total+(total*0.07))
Itās crucial to split the input otherwise the output number will be much higher than expected.
+ 1
x = input().split(" ")
menu = {"Pizza"}
sum = 0
for i in x:
if i=="Pizza":
sum +=6
elif i=="Nachos":
sum +=6
elif i=="Cheeseburger":
sum+=10
elif i=="Water":
sum+=4
else:
sum+=5
fsum = sum + (sum*7)/100
print (fsum)
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
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
0
I'm still a beginner, so my code was a little longer/ less efficient than some of these others, but here's what worked for me:
#include <iostream>
#include <string>
using namespace std;
void orders(string ordArr[], int size)
{
int f = 0;
for (int i = 0; i < size; ++i)
{
if (ordArr[i] == "Cheeseburger")
f += 10;
else if (ordArr[i] == "Nachos")
f += 6;
else if (ordArr[i] == "Pizza")
f += 6;
else if (ordArr[i] == "Water")
f += 4;
else
f += 5;
}
int subtotal = f;
float tax = subtotal * 0.07;
float total = f + tax;
cout << total << endl;
}
int main()
{
string arr[4] = {"", "", "", ""};
cin >> arr[0] >> arr[1] >> arr[2] >> arr[3];
orders(arr, 4);
return 0;
}
0
eindToaal = 0
etenBestellen = {
"Nachos": 6,
"Pizza": 6,
"Cheeseburger": 10,
"Water": 4,
"Coke": 5
}
def rekening(x):
subTotaal = 0
if x in etenBestellen:
subTotaal += etenBestellen [x]
return subTotaal
else:
subTotaal += 5
return subTotaal
a,b,c,d = input().split()
#print(a,b,c,d)
subTotaal = rekening(a) + rekening(b)+rekening(c)+rekening(d)
eindToaal = subTotaal *1.07
print (round(eindToaal, 2))