 Ballpark Order Challenge | Sololearn: Learn to code for FREE!

0

# 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}')

+4

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

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.

+1