Print the output of compute_bill


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

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

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

for key in prices:
-- print key
--print "price: %s" % prices[key]
--print "stock: %s" % stock[key]
--print total

def compute_bill(shopping_list):
--for key in shopping_list:
--if stock[key]>0:
---- total=prices[key]+total
--return total

call compute_bill(shopping__list) #?? I'm not sure how I'm supposed to call it.

My teacher wants me to print the output function of compute_bill witth shopping_list as the argument.


We can write this line to include a generic parameter variable, such as,

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

The call to the function with shopping_list as argument...



So all I really need to do is type
"print compute_bill(shopping_list)"?


That's it, just not in quotes. As we have seen, it matters not what we call the parameter variable, and even if we use the name in both argument and parameter, they are two separate variables, one local, the other global. A good practice would be to not use the same name so your code is more easily readable.


Oh ok. Thank you! I did notice how you can use any variable.

I'm actually stuck on a different project. It seems really simple but I've been trying to get it for a few days now..