+ 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.
+ 2
What is on case #5 as input?
+ 2
Jayakrishna🇮🇳 ,
the task is from code coach in community section: 'ballpark orders'
+ 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)
+ 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
+ 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.
+ 1
Can you add task link or Lesson number?
Try
print( round(total, 2))
+ 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.
+ 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...
0
Yeah cause it's not an issue of rounding. Look at my answer silly
0
Lothar good approach.
Also including taxes on that switch will help make the code shorter .
total += 60+(60*0.07)