Making a Purchase


#1




Getting this response:

Oops, try again. compute_bill(['apple']) resulted in a NameError: global name 'food' is not defined

I've figured out that I should replace 'def compute_bill(shopping_list):' to (food) instead of shopping list... but I don't understand why? Aren't I pulling from the list shopping_list? food doesn't exist outside my function and isn't attach to any value... How does that work?


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


#2

It is the object that will be passed in the call argument:

compute_bill(shopping_list)

#3

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