+ 1

Hi i need some back up

im doing this task: 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 im almost done, the only part that im missing is the part of adding in case that something is not in the menu a coke instead. The code if you test it works but not in the part o the coke. Any help is appreciated :) https://code.sololearn.com/c47tZpL185i8/?ref=app https:

17th May 2023, 3:35 AM
Alan Restrepo
Alan Restrepo - avatar
15 odpowiedzi
+ 6
Try this code: [ This is my code using Functions] This code defines a function called 'calculate_total_cost' that takes a list of food items as input. It uses a dictionary 'menu' to map food items to their corresponding prices. The function iterates over each item in the input list and checks if it exists in the 'menu' dictionary. If found, it adds the price to a 'total_cost' variable; otherwise, it adds the price of a 'Coke'. The function then applies a tax factor to the 'total_cost' to include tax, rounds the result to two decimal places, and returns it. The code prompts the user for input, splits the input into individual items, calls the 'calculate_total_cost' function with the items, and prints the resulting total cost. https://code.sololearn.com/c20hv3owt9re/?ref=app
17th May 2023, 3:51 AM
Vibhor
Vibhor - avatar
+ 6
#This is your optimized code Alan Restrepo total = [] user_input = input() menu = ['Nachos', 'Pizza', 'Cheeseburger', 'Water', 'Coke'] nachos = 6.00 pizza = 6.00 cheeseburger = 10.00 water = 4.00 coke = 5.00 for item in user_input.split(): if item in menu: if item == 'Nachos': total.append(nachos) elif item == 'Pizza': total.append(pizza) elif item == 'Cheeseburger': total.append(cheeseburger) elif item == 'Water': total.append(water) elif item == 'Coke': total.append(coke) else: total.append(coke) subtotal = sum(total) tax = subtotal * 0.07 total_cost = subtotal + tax print(total_cost)
17th May 2023, 4:04 AM
Vibhor
Vibhor - avatar
+ 5
Alan Restrepo The modified code replaces the separate variables a, b, c, d and e with a loop to iterate through each item in the user's input. If the item is on the menu, its price is added to the 'total' list.otherwise, a Coke price is appended. The unnecessary variables z, f1 and f2 are removed. The mistake in the original code was the incorrect calculation of tax and subtotal. That code was not handling items not on the menu by substituting a Coke. The code which I have edit of yours give the correct calculation of the total cost, accounting for all menu items and items not on the menu.
17th May 2023, 4:10 AM
Vibhor
Vibhor - avatar
+ 5
Orin Cook 😂😂😂😂
17th May 2023, 4:36 AM
Vibhor
Vibhor - avatar
+ 5
Nahh Orin Cook it made him understand and explained his mistakes. Didn't I? Better to provide solution with explanation rather than let him just guessing the code and solution which will eventually waste his time.
17th May 2023, 4:38 AM
Vibhor
Vibhor - avatar
+ 3
Vibhor don't just give people the finished solution lol, nobody learns anything that way.
17th May 2023, 4:11 AM
Orin Cook
Orin Cook - avatar
+ 1
Since you're eventually doing user_input.split() anyway, it might make your life easier to do that first
17th May 2023, 4:04 AM
Orin Cook
Orin Cook - avatar
+ 1
Vibhor jesus crist bless you, thank you so much for the help, thanks for the first code and for show me a better version of my code. this is the kind of help that makes people advance and learn, now i know how to do it better, thanks so much again.
17th May 2023, 4:11 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
Vibhor EXACTLY! that's why ere something call schools and teachers. thanks aging man
17th May 2023, 4:41 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
Vibhor because even in the schools are professors like him that don't help the students understand what they are explaining to their own students. thanks man
17th May 2023, 4:43 AM
Alan Restrepo
Alan Restrepo - avatar
0
Orin Cook bro you are not helping at all, i learn of some body that its explaining me what my mistakes are and showing me the correct way to do it, all people don't learn the same, if you learn by you own and without help of any body good for you but if you are not going to give something that help some one keep quiet. what he did is teaching the right way, for people like you others cant learn.
17th May 2023, 4:19 AM
Alan Restrepo
Alan Restrepo - avatar
0
Rr
17th May 2023, 3:55 PM
Laba Singha
0
Heloooou
18th May 2023, 12:30 PM
Semra Memedoska
Semra Memedoska - avatar