Items (or values!) in stock will not add up


12. Stocking out

It adds up to 4 instead of the correct 7.

I expect it to add up. I try using the word item, value and key - none of get the right result. (It seems that the word value should work because that is the exact thing in the dictionary we are being asked to add.)

Replace this line with your code. 
def compute_bill(food):
    total = 0
    for item in food:
        if (stock[item] > 0):
            total += prices[item]
            stock[item] = stock[item] - 1
            return total


return is inside the if block when it should be outside the for loop block

def ___:
    for ___:

    return ___


ok. that works. thank you! one quick question just so I understand why is it item that we are adding and not value? The values are exactly what we are being asked to add. Am I wrong?


The item is the key associated with the value. list[item] is that value.

key : value


ok. got it. thank you.


2 posts were split to a new topic: Keep getting this error message

Keep getting this error message

i got it! it was just the indentation error.