+ 1
Ballpark Order Challenge
I can't figure out why this is not working for the 5th test. order=input().split() #order =["Piza","Cheeseurger","Waer","Ppcorn"] total=0 for i in order: if "Nachos" in i: total+=6.0 elif "Pizza" in i: total+=6.0 elif "Cheeseburger" in i: total+=10.0 elif "Water" in i: total+=4.0 elif "Coke" in i: total+=5.0 else: total+=5.0 taxed=round(total*1.07,2) print (f'{taxed:.2f}')
12 Respostas
+ 6
I edited your code by replacing "in" with "==" for the rest of the conditional statements and it solved the issue.
order=input().split()
total=0
for i in order:
if "Nachos" == i:
total+=6.0
elif "Pizza" == i:
total+=6.0
elif "Cheeseburger" == i:
total+=10.0
elif "Water" == i:
total+=4.0
elif "Coke" == i:
total+=5.0
else:
total+=5.0
taxed=round(total*1.07,2)
print (f'{taxed:.2f}')
+ 2
Derick Smith Did you try the fix I provided, because it is definitely working for me.
+ 1
John Wells The task does specify that "If one of your friendâs orders something that isn't on the menu, you will order a Coke for them instead." though.
https://www.sololearn.com/coach/15?ref=app
+ 1
Sorry just saw it now, thank you so much. I can't seem to understand why the in does not work. The fist test is four waters and the old code worked there.
+ 1
Brilliant! I bet your right.
0
What is the fifth test?
0
It is hidden. I thought it was just the decimal place but I have tried both rounding and formatting to fix the output.
0
Thanks to everyone, for the attempted answers. The code does work for duplicate items so I think the in is working. I have also tried with and without the rounding with no fix. It must be some assign thing with the 5th test. My only guess is some form of weird rounding. I will just have to keep trying it. If anyone gets z fix let me know.
0
Derick Smith It is kind of weird. Although not semantically accurate, the 'in' should work since "test" in "test" returns true.
I hypothesize that one of the items in the final test was a substring of one of the items in the list. Hence, for example,
"Cheese" in "Cheeseburger"
or
"Water" in "Watermelon"
returned true, and the price of whatever you were checking for was charged instead of coke. This is the most probable case which took place.
0
food = input()
food = food.split(" ")
cost = 0
for x in food:
if x == 'Nachos':
cost += 6.00
elif x == 'Pizza':
cost += 6.00
elif x == 'Cheeseburger':
cost += 10.00
elif x == 'Water':
cost += 4.00
else:
cost += 5.00
tax = cost * .07
total = tax + cost
print(total)
0
order=input().split()
for i in order:
if i=="Nachos":
n+=1
elif i=="Pizza":
p+=1
elif i=="Cheeseburger":
ch+=1
elif i="Water":
w+=1
elif i="Coke":
c+=1
else:
o+=1
cost=(n+p)*6.0+ch*10.0+w*4.0+(c+o)*5.0
print (round((cost)*1.07,2))
0
Hi guys, I have successfully passed all test cases. If you want, you can take it.
menu = {
"Nachos":6,
"Pizza":6,
"Cheeseburger":10,
"Water":4,
"Coke":5
}
order = input()
order = order.split(" ")
sum = 0
tax = .07
for x in order:
if x in menu:
sum+=menu.get(x)
else:
sum+=menu.get("Coke")
print(sum+(sum*tax))