+ 1
Ballpark Orders
Hi, I know there is better and more efficient ways to answer this (dictionary) but I was just wondering why the code bellow does not pass Test Case #2 (Passes everother test): order = input().split(" ") amount = 0 for food in order: if food == "Nachos" or food "Pizza": amount += 6 elif food == "Cheeseburguer": amount += 10 elif food == "Water": amount += 4 else: amount += 5 print(amount + (amount * 7) / 100) For the test "Cheeseburguer Cheeseburguer Coke Water" my output is 20.33 I just want to understand the mistake in the logic
4 odpowiedzi
+ 5
Davide Araujo Solved it. Took me a while because im blind but its pretty hard to see. Im guessing english is not your frist language and your logic is 100% correct good job. the problem is you spelt Cheeseburger wrong. So in your elif just make that quick fix and you should be fine.
❌ Cheeseburguer
✅ Cheeseburger
+ 2
order = input().split(" ")
amount = 0
for food in order:
if food == "Nachos" or food == "Pizza": # Added the equality comparison operator (==)
amount += 6
elif food == "Cheeseburguer":
amount += 10
elif food == "Water":
amount += 4
else:
amount += 5
print(amount + (amount * 7) / 100)
The mistake in the logic of your code lies in the conditional statement for checking if food is equal to "Nachos" or "Pizza". You missed the equality comparison operator (==) after food == "Nachos" in the if statement.
+ 1
Lol, ty so much. A real headscracher for some time now x)
Thank you for taking the time
+ 1
Davide Araujo Welcome