A day at the supermarket - Stocking out


#1



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: global name 'item' is not defined


It looks fine to me, can someone tell me whats wrong?


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


 



#2

for stock[item] in food:

why use stock[item] as your iterator?

the iterator gets assigned each item in the food list, so then simply using item would make more sense


#3

Thanks that fixed it


#4