+ 1
Code Coach Ballpark Orders - Can't spot my mistake
Hey folks, maybe someone can point my mistake out to me? 4 out of the 5 tests are positive, but the fifth hidden one isn't. In my mind my code should work.. I'd appreciate if someone can tell me what my mistake is. Here's my code: order=input() total=0 menu=["Pizza","Nachos","Cheeseburger", "Water","Coke"] i=0 x=0 while i < 5: if order.count(menu[i])>0: x=x+order.count(menu[i]) if i==0 or i==1: total=total+6*order.count(menu[i]) elif i==2: total=total+10*order.count(menu[i]) elif i==3: total=total+4*order.count(menu[i]) else: total=total+5*order.count(menu[i]) i+=1 total=total+(4-x)*5 total=total*1.07 print(round(total,2)) Thanks, and best regards, Aaron
4 Answers
+ 3
Suppose your friend orders Fries. How does your code handle this case?
+ 3
Ah, I think I get the idea!
Suppose your friend orders Watermelon. Your code finds "Water", and adds "Water" instead of "Coke". Could that be the issue?
Check this one:
https://www.sololearn.com/Discuss/3257154/?ref=app
+ 1
I did the following: the variable "x" counts how many orders were made from the menu. So if all orders were from the menu, then x is 4 and nothing is added. But if someone ordered Fried or anything else of the menu, the x counter would be lower than 4 and I would order that many Cokes. (the code line: total=total+(4-x)*5)
That should work fine right?!
0
Oh absolutely, that makes sense. I didn't consider that option.
Thanks for your help Lisa! I appreciate it.