12/13 What is wrong please


#1
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 += prices[item]
            stock -= 1
        
    return total

This is my code but I keep getting the error.

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

Can someone please show me where I am going wrong?


#2

Got the answer now, when I try and remove a value from stock i did not have an item next to it.

stock[item] -= 1