Q:

Result wasn't printing, why is `print` ignored after `return`?

I'm working through the beginner's Python course in CodeAcademy. This is part of one of the exercises, where you're "checking out" at a grocery store, but I wanted to the code to print the final bill/"total" rather than just returning "total". I don't understand why it's not printing. I have tried putting it at the end, after the iteration, and, as here, within the recursion to see if it'll print after each step. When I run this code, nothing displays. 
shopping_list = ["banana", "orange", "apple"]

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

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

Thankyou - so I now understand that everything is ignored after return total - a better question might be why is this?
Is there a situation where you would include print total after return total in this way and not wish both to happen?

A:

I like your approach, as it is well structured and the flow of the program is clear. However, you have not quite the right syntax for calling functions. With your current layout you need to do like this:
shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}

prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

#food = shopping_list # Not needed as it is used as input parameter

def compute_bill(food):
    global stock # Not strictly needed, see below.
    total = 0
    for item in food:
        if stock[item]>0:
            total += prices[item]
            stock[item] -=1
    return total

print compute_bill(shopping_list) # Calling function and printing result

One other thing that may bite you in the future is that generally it is not possible to update a global variable stock within a function, because for most variables it is only a copy that is available for the function and that copy is not writable, if it is not in the input parameter list - unless the keyword globalis used. However, for dictionaries (and lists and other collections) the global keyword is not needed.

