Stocking out problem


#1

I wrote this code:

shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

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

but it says, that for some lists it doesnt work. Can anyone help me or just send correct code and ill try to find my mistake for my own?


#2

sending correct code is in violation of the guidelines, but we can help you.

from the instructions:

If the item is in stock and after you add the price to the total, subtract one from the item's stock count

you don't reduce the items stock:

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

see if you can discover how to reduce stock, if you can't figure it out, post an updated version of your code and you will be helped further


#3

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