QUESTION: the directions in previous steps was to use "food" as the argument - how come "food" did not need to be defined? does python automatically recognize the fruits as food items?

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


As you have said, food is an argument. You can consider it like an x argument in a function f(x) where x can be replaced with any number. In this case, food can be replaced with shopping_list.
Reason why you put food as the argument and not just shopping_list is because perhaps you will use this function for another food list or do other fancy things.

Python won't automatically recognize it unless you call the function with shopping_list as your replacement of the food argument such as


The reason why you think it's automatic is because Codecademy's SCT running to check if your code is correct (it quietly does it).


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