+ 1

Can someone help me (btw im using python)

https://www.sololearn.com/coach/15?ref=app Can someone tell me whats wrong with my code please? I've been working on this for hour... You and three friends go to a baseball game and you offer to go to the concession stand for everyone. They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. Water is $4.00 and Coke is $5.00. Tax is 7%. Task Determine the total cost of ordering four items from the concession stand. If one of your friend’s orders something that isn't on the menu, you will order a Coke for them instead. Input Format You are given a string of the four items that you've been asked to order that are separated by spaces. Output Format Yo total = 0 i = 4 while i>0: order=input() if order=="Water": total+=4 if order =="Cheeseburger": total+=10 if order == "Nachos": total+=6 if order == "Pizza": total+=6 if order == "Coke": total+=5 i-=1 print (total)

3rd Aug 2021, 8:20 AM
Ervan
Ervan - avatar
7 Respostas
+ 4
Hi Ervan! It is always better to use for loop when you know the loop should execute n(here 4) times. In input format, they're asking you to separate inputs by spaces. split() is here to do the job for it. You're missing to consider the tax amount in your final total. Here it is my solution for you. https://code.sololearn.com/c4uPcJSy3Be2/?ref=app
3rd Aug 2021, 10:04 AM
Python Learner
Python Learner - avatar
+ 2
total = 0 i = 4 while i>0: order=input() if order=="Water": total+=4 elif order =="Cheeseburger": total+=10 elif order == "Nachos": total+=6 elif order == "Pizza": total+=6 elif order == "Coke": total+=5 else: total+=5 i-=1 print (total) #check for this
3rd Aug 2021, 8:41 AM
Atul [Inactive]
+ 1
Ervan How about this one? :- print(sum((4 * (x == "Water") + 10 * (x == "Cheeseburger") + 6 * (x == "Nachos" or x == "Pizza")) or 5 for x in input().split()) * 1.07) # Hope this helps
5th Aug 2021, 6:43 AM
Calvin Thomas
Calvin Thomas - avatar
0
Can't access the question as it is a pro question. So please post the question
3rd Aug 2021, 8:33 AM
Atul [Inactive]
0
It looks like the line 'i-=1' is wrongly indented ending up inside the if block when it should be outside of it
3rd Aug 2021, 8:35 AM
Giorgos
0
Actually that on is fine when i see the result the problem was "the input"
3rd Aug 2021, 8:36 AM
Ervan
Ervan - avatar
0
Use elif operator also the else operator. And put the cost of coke
3rd Aug 2021, 8:39 AM
Atul [Inactive]