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


#1



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


#2

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

def ___:
    for ___:

    return ___

#3

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?


#4

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

key : value

#5

ok. got it. thank you.


#6

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


Keep getting this error message
#7

i got it! it was just the indentation error.


#8