Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
Xander Encio , the code you did is difficult to debug for me since i am working currently on a reduced screen size. if nobody has an idea where the issue is, i would suggest you to re-write the code. start here: food = input().split() # split the input sentence to a list total = 0 # crreate and initialize a variable that should hold the running sum for x in food: # iterate on the list of food items coming from input if x == "Nachos": total += 6.0 elif x == ... ... ... ... else: total += 5.0 # this for all items that are not available # calculate the tax and round the result to 2 digital places and output it this will not be the the most efficient version, but it has a good structure and readability.
17th Sep 2022, 6:18 PM
Lothar
Lothar - avatar
+ 2
What is on case #5 as input?
17th Sep 2022, 3:46 PM
John Doe
John Doe - avatar
+ 2
Jayakrishna🇮🇳 , the task is from code coach in community section: 'ballpark orders'
17th Sep 2022, 4:06 PM
Lothar
Lothar - avatar
+ 2
This is what I used for that. menu = { "Nachos":6.00, "Pizza" :6.00, "Cheeseburger":10.00, "Water":4.00, "Coke":5.00 } order = input().split(" ") price = 0.00 for item in order: if item in menu: price += menu[item] else: price += menu['Coke'] final_price = price + (price * 7) / 100 print (final_price)
18th Sep 2022, 7:05 AM
James Lewis
James Lewis - avatar
+ 2
Jayakrishna🇮🇳 , maybe you have overseen the first 2 line of my sample code. if input is "vegPizza" it uses a price of 5.0 because this food is not covered by the if branches. have a look at the complete code in playground: https://code.sololearn.com/cw6EoacLg1lT/?ref=app
18th Sep 2022, 11:05 AM
Lothar
Lothar - avatar
+ 1
Your variable count5 looks for instances of the string "Coke". In the project description it states that your friend may order anything that's not on the menu, but instead you will buy a coke. When you just search for "Coke" it won't include any of the other possibilities that could be entered.
17th Sep 2022, 1:19 PM
Slick
Slick - avatar
+ 1
Can you add task link or Lesson number? Try print( round(total, 2))
17th Sep 2022, 1:34 PM
Jayakrishna 🇮🇳
+ 1
Ok. Lothar 👍 fine. I just checked it. It should work but i guess with this approach, it may fail if input contains "vegPizza" , should be replaced with coke's price but your approach takes Pizza price. Xander Encio Instead Take input list items = input().split() #it works. Only 4 words input have.
17th Sep 2022, 8:07 PM
Jayakrishna 🇮🇳
+ 1
Lothar It's not about your code. Only first line is about you, thanking for mentioning task "source". Rest is all about OP code, of checking by items.count("Pizza") #sample. It returns 1 for "VegPizza".count("Pizza") # which leads to wrong output.. #sry if I confused...
18th Sep 2022, 11:48 AM
Jayakrishna 🇮🇳
0
Yeah cause it's not an issue of rounding. Look at my answer silly
17th Sep 2022, 4:03 PM
Slick
Slick - avatar
0
Lothar good approach. Also including taxes on that switch will help make the code shorter . total += 60+(60*0.07)
17th Sep 2022, 7:04 PM
John Doe
John Doe - avatar