Stocking out


#1

I'm having some trouble wrapping my head around this part.

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

I know item is a variable defined by the for statement, and that it relates to food, so I guess I'm uncertain how it relates to food in this case, since food is the argument of compute_bill. I must be expecting the name food to be the name of one of the lists or dictionaries. Would you be able to give more insight about how these arguments relate to the rest of the code, or how they call certain variables? Hopefully I'm not asking you to repeat an answer you gave in this thread already. Any help is much appreciated, thanks!


Stocking out
#2

food is the function parameter, a function parameter serves as a placeholder until you call the function. Then the value you supply when calling the function gets into food function parameter

so if you supply shopping_list as argument, food will now contain the shopping_list


#3

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