Stocking Out


Im having a hard time comprehending the directions.
Here are the directions:
Make the following changes to your compute_bill function:

1.While you loop through each item of food, only add the price of the item to total if the item's stock count is greater than zero.
2.If the item is in stock and after you add the price to the total, subtract one from the item's stock count.

I got the first part but the second part im confused on it.
Here is my code:

def compute_bill(food):
    total = 0
    for item in food:
        if stock[item] >0
        total += prices[item]
    return total

I appreciate the help.


There is a colon missing at the end if your if statement:

if stock[item] >0 <- missing semi-colon

Which means the next line needs to be re-indented. After you added an item, you should reduce an item from the stock.


if stock[item] > 0:
total += prices[item]
stock[item] -= 1
return total
does that look right? plus the indentation after the if statement.


yes, that looks fine. But instead of a single backtick on each line:

`if stock[item] > 0:`

try to insert 3 backticks before and after your code so indent will show:

if stock[item] > 0:
     total += prices[item]
     stock[item] -= 1
return total


You mean here in the Q and A form? Not in the actual code, right?


Yea, on the forum of course, not in the exercise


2 posts were split to a new topic: Stocking out