Stocking Out: PLEASE HELP


This is my code so far but this lesson is realllllllllly confusing me. Can someone please explain this to me? TNX

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


you are pretty close, but there is one small problem here:

total = prices[item] + total

only if the item is in stock, should you increase the total, you can charge customers for products that are not in stock


So how should i change my code?


already mentioned this:

what determines if the item is in stock? And how could we make sure total is only increased when item is in stock?


Add an indent before the total = prices[item] + total and your code will work


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.