Discussion about for and in


A Day at the Supermarket - Making a purchase

I got my code to work but I don't quite understand why it does.

def compute_bill(food):
for items in food:
total += prices[items]
return total

In line 3 I call "for items in food". What does food represent because none of my lists or dictionaries are called that. I'm confused by how you can use food and it makes computations.

Replace this line with your code.


We are given a grocery list in the exercise setup. We write the funciton then pass that list as the argument in our function call.

def compute_bill(food):
    # function block code


In this instance, food is the locally defined reference to the grocery_list object. When we are iterating over food we are actually iterating over gocery_list.