compute_bill(['apple']) returned 117.0 instead of 2 HELP!?


#1

I'm stuck at this exercise: A day at the super market
https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/2?curriculum_id=4f89dab3d788890003000096

I keep getting this error message

Oops, try again. compute_bill(['apple']) returned 117.0 instead of 2

What am i doing wrong and how do i correct it??


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 food in prices:
        total = total + stock[food] * prices[food]
    return total


#2

Hi

I spotted two problems in the function compute_bill :

1) The for loop must iterate on the items contained in the list food and not the list prices

2) The total is computed by adding each prices together, not the products of stock and prices.

Cheerio


#3

Thanks! @thebelgian1