Need help figuring out code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need help figuring out code

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 You will output a number of the total cost of the food and drinks. Sample Input 'Pizza Cheeseburger Water Popcorn' Sample Output 26.75 My code order = input() sum = 0 if order == "Nacho": sum += 6 elif order == "Pizza": sum += 6 elif order == "Cheeseburger": sum += 10 elif order == "Water": sum += 4 elif order == "Coke": sum += 5 else: sum += 5 print ((sum) + ((sum * 7) / 100))

3rd Jul 2022, 8:00 PM
Irem Majid
Irem Majid - avatar
4 Answers
+ 8
Your problem is that you get one string with 4 orders but you only check for one order once… Try to do order.split() to get a List with every order… And then just iterate trough the list while adding up the price.
3rd Jul 2022, 8:08 PM
Janne
Janne - avatar
+ 1
Emerson Prado Yeah thats true… Next time I wont post it instantly 👍
4th Jul 2022, 5:31 PM
Janne
Janne - avatar
0
if you want the solution: order=input().split() total = 0 for i in order: if i=="Water": total+=4 elif i=="Cheeseburger": total+=10 elif i == "Nachos": total+=6 elif i == "Pizza": total+=6 elif i == "Coke": total+=5 else: total+=5 print (total*1.07)
3rd Jul 2022, 8:11 PM
Janne
Janne - avatar
0
Janne Pls avoid answering with finished code. This makes the OP skip an important learning step.
4th Jul 2022, 5:04 PM
Emerson Prado
Emerson Prado - avatar