Open
+ 1

# Help with ballpark problem!

Am i on the right track even? fullorder = input() order = fullorder.split cokes = 0 pizza = 0 nachos = 0 cheeseburger = 0 water = 0 menuitems = ["Pizza", "Cheeseburger", " Coke", "Water", "Nachos" ] if order not in menuitems: cokes += 1 for word in fullorder: if word == "Coke": cokes += 1 if word == "Pizza": pizza += 1 if word == "Nachos": nachos += 1 if word == "Water": water += 1 if word == " Cheeseburger": cheeseburger += 1 cokeprice = cokes * 5.00 pizza_nachoprice = (pizza + nachos) * 6.00 burgerprice = cheeseburger * 10.00 waterprice = water * 4.00 totalcost = (cokeprice + pizza_nachoprice + waterprice + burgerprice) * 1.07 print(totalcost)

29th Feb 2020, 1:48 AM
Brenner Pieszak
+ 3
order = input().split(' ') cokes = 0 pizza = 0 nachos = 0 cheeseburger = 0 water = 0 menuitems = ["Pizza", "Cheeseburger", "Coke", "Water", "Nachos" ] for word in order: if word == "Coke": cokes += 1 elif word == "Pizza": pizza += 1 elif word == "Nachos": nachos += 1 elif word == "Water": water += 1 elif word == " Cheeseburger": cheeseburger += 1 else: cokes += 1 cokeprice = cokes * 5.00 pizza_nachoprice = (pizza + nachos) * 6.00 burgerprice = cheeseburger * 10.00 waterprice = water * 4.00 totalcost = (cokeprice + pizza_nachoprice + waterprice + burgerprice) * 1.07 print(totalcost)
29th Feb 2020, 1:57 AM
Hatsy Rei
+ 2
There is a much simpler way if you are willing to use dictionaries. But even without it, you can shorten your code by introducing the variable which stores the total early on in your program. order = input().split(' ') total = 0 menuitems = ["Pizza", "Cheeseburger", "Coke", "Water", "Nachos" ] for word in order: if word == "Coke": total += 5 elif word == "Pizza": total += 6 elif word == "Nachos": total += 6 elif word == "Water": total += 4 elif word == " Cheeseburger": total += 10 else: total += 5 print(total*1.07) Remember to handle printing only 2 decimal places.
29th Feb 2020, 2:01 AM
Hatsy Rei
+ 1
Thank you !
29th Feb 2020, 2:08 AM
Brenner Pieszak
0
I should change if order not in to : If word not in menu items, but that diesnt change the first test case not working!! Thanks
29th Feb 2020, 1:53 AM
Brenner Pieszak
0
order = input().split(' ') total = 0 menuitems = ["Pizza", "Cheeseburger", "Coke", "Water", "Nachos"] for word in order: if word == "Coke": total += 5 elif word == "Pizza": total += 6 elif word == "Nachos": total += 6 elif word == "Water": total += 4 elif word == " Cheeseburger": total += 10 else: total += 5 print(total * 1.07) This still doesnt work...it seems to be exactly what you posted? :(
29th Feb 2020, 6:07 PM
Brenner Pieszak