A day at The supermarket


#1

Even though my code is correct it's still displaying an error

This is the question

        Define a function compute_bill that takes one argument food as input.In the function, create a variable total with an initial value of zero.For each item in the food list, add the price of that item to total.Finally, return the total.

Ignore whether or not the item you're billing for is in stock.

Note that your function should work for any food list.

this is my answer

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

Write your code below!

def compute_bill(food):
total = 0
for key in prices:
if key == food:
total = prices[key] + total
return total
print compute_bill('apple')

after calling below function i am getting the output but the compiler says it's not right .PLease help me rectify the problem


#2

Quote from instructions:

For each item in the food list, add the price of that item to total.

food is list, not string.


#3

I finally got it to work.I tried to go through the list(food).You're correct.Thanks a lot