Stocking out


#1



I have looked on every help forum here and I still haven't been able to fix my problem

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096#

Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana caused the following error: local variable 'stock' referenced before assignment


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 item in food:
        if stock[item] > 0: 
            total = total + (prices[item])
            stock -= 1
    return total


#2

You need to look closer at this part


#3

confusing error, anyway, the problem is here:

stock -= 1

stock is a dictionary. You don't want to reduce the dictionary by one, you want to reduce a item in dictionary by one:

stock[item] -= 1