Stocking Out 12 correct code not passed


Receive this error message: Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 69 instead of the correct 7

correct computation of total price

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):
    for item in food:
        if stock[item]>0:
            total += prices[item] * stock[item]
    return total


are you sure about this line:

total += prices[item] * stock[item]

The moment your order one item, you pay the price of the item * number of items in stock.

No need to multiply it, just add the price of the item to the total:

total += prices[item]


Oops, it seems i was hasty with my answer, now this line:


the moment your order one item, the whole stock is sold out. I would just subtract one:

stock[item] -= 1

I like your business plan, the moment a customer buys one item, give them the entire stock of that item and make them pay for it, it makes good money :slight_smile: (in case it wasn't obvious, that was just a little joke )