+ 4

Hello, i need some help whith a task/project

this is the task that im trying to do: 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 the problem that im having is that i don't know ho to make the part that if one of my frineds whant's something that is not in the menu, the program has to put insted a coke, if somebody knows how it would be a great help. https://code.sololearn.com/

8th May 2023, 7:47 AM
Alan Restrepo
Alan Restrepo - avatar
14 Respostas
+ 7
Alan Restrepo , (please forget my last post, this was given by accident - sorry!) here are some hints: > the items that can be purchased has to start with an *upper case letter* currently count() returns 0 for all items. > inside the *if conditionals* are print statements that are *not required*. should be removed. > for the final price the tax is missing. > to handle items that are not defined, we have to split the input to individual words. this creates a list of all items. now we can iterate over this list and handle all known items, as well as also the unknown items.
8th May 2023, 9:34 AM
Lothar
Lothar - avatar
+ 5
Alan Restrepo , here is a link to a short tutorial about for loops: (i also recommend you to start learning from the tutorial: *introduction to python*) https://www.sololearn.com/learn/Python/2435/?ref=app
8th May 2023, 9:54 AM
Lothar
Lothar - avatar
+ 3
Also consider using a switch statement instead here, with coke left for your default case. That way anything not defined automatically becomes a coke.
8th May 2023, 3:04 PM
Orin Cook
Orin Cook - avatar
+ 3
Emerson Prado whoops, I didn't notice that. I guess you're right. It's not helpful to give finished code as feedback
9th May 2023, 5:28 PM
Junior Coder
Junior Coder - avatar
+ 2
Please share the code
8th May 2023, 8:50 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 2
Alan Restrepo don't share the code like that, you can see the insert button click on it, then go to insert code click on it, then you can see the top drop-down menu click on it, you can see the my code bits click on it then share the code
8th May 2023, 9:27 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 2
Neg Tee Pls avoid giving finished code as answer, because it makes the OP skip the most important part of learning. Prefer giving hints for the OP to find the solution instead.
9th May 2023, 12:37 AM
Emerson Prado
Emerson Prado - avatar
+ 1
Sakshi sure here you go: total = [] user_input = input() a = user_input.count('nachos') b = user_input.count('pizza') c = user_input.count('cheeseburger') d = user_input.count('water') e = user_input.count('coke') nachos = 6.00 pizza = 6.00 cheeseburger = 10.00 water = 4.00 coke = 5.00 if a > 0 : mul_1 = nachos * a total.insert(0, mul_1) print (mul_1) if b > 0 : mul_2 = pizza * b total.insert(1, mul_2) print (mul_2) if c > 0 : mul_3 = cheeseburger * c total.insert(2, mul_3) print (mul_3) if d > 0 : mul_4 = water * d total.insert(3, mul_4) print (mul_4) if e > 0 : mul_5 = coke * e total.insert(4, mul_5) print (mul_5) print (sum(total))
8th May 2023, 8:59 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
Lothar i know that fails in all test cases, is not complete, i have been working in this code for some days now the only two parts that I need to finish is the final result of the total price that I know how to do it, and the other one that I mention on the question. Some times I good to give a hint or a tip but some times if you know how to do something and you can show it to some one that doesn't know how, its more helpful, when is something that you been struggling to do and don't have a clue, at least is what I do when I can. If I have the final part i could finish by my self the code if I knew how to do it I wouldn't be asking for help
8th May 2023, 9:26 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
Hi! I tried to solve your problem and here's what I think: 1. Get the string as input then split it into individual words 2. Declare a variable (eg sum) to store the total price 3. Loop through the array and add the corresponding price to the sum variable for each element of the array 4. After that, add 7% tax to the total price. I hope I helped and answered your question!
9th May 2023, 4:26 PM
Junior Coder
Junior Coder - avatar
+ 1
Junior Coder Pls see my last answer!
9th May 2023, 5:08 PM
Emerson Prado
Emerson Prado - avatar
0
Sakshi I did it
8th May 2023, 9:31 AM
Alan Restrepo
Alan Restrepo - avatar
0
Lothar lol, yeah I know about the print statements that don't are necessary, i just use them for like some sort of sign that the code is working, i know about the tax you right, i know how to do it I just need to implement it, and about the split of the input , i feel from the beginning that I could use a loop, a for loop actually but I don't know how to, that's the thing I have an idea of how to do it I just don't know how to implement it in the code
8th May 2023, 9:44 AM
Alan Restrepo
Alan Restrepo - avatar
0
tried to follow the logic of your code, in the end you need to calculate not_in_menu items, which probably will result in a mul_6, : (how many items are in the order list) - (sum of all your input.counts a,b,c,...) not_in_menu = len(user_input.split(" ")) - (a+b+c+d+e) mul_6 = coke * not_in_menu total.insert(5, mul_6) # add TAX TAX = 7 final_price = sum(total)*(1+TAX/100)) i also would share my code using a dictionary as a menu : menu = { 'Nachos' : 6, 'Pizza' : 6, 'Cheeseburger' : 10, 'Water' : 4, 'Coke' : 5, 'TAX' : 7 } # order = input("Please Order : ") order = 'Pizza Cheeseburger Water Popcorn' # 26.75 price = 0 order_list = order.split(" ") for item in order_list : #print (item) if item in menu : price = price + menu[item] else : price = price + menu['Coke'] final_price = price * (1+menu['TAX']/100) print (final_price) * please consider that lower/upper case issue for inputs is not addressed in your code, nor mine :)
8th May 2023, 11:36 PM
Neg Tee
Neg Tee - avatar