Issues with 'stocking out'


This is my current 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]
            stock[item] -= 1
        return total

I've tried several variations to the code - including many suggested in similar post like this that folks said worked - but nothing works for me.

Please help


Numbered in the thousands.

We cannot tell what your problem is because we don't know the blocking. Please see the pinned article on the topic of code sample formatting in posts.


sorry - i keep forgetting that this is not a simple a text editor.

What can you tell me about error in the code?


The return is indented too far. It should be outside of the for block.


thanks - it worked perfectly


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