# That food thing in the loop makes no sense (11. Making Purchase)

#1

the code works fine, but i dont understand, where food comes from? i mean i have my shopping_list, but i do loop through a list with the name food? which i dont see created somewhere?

well i expected that i have to use the shopping_list or create a list with teh name food. would be nice if somebody can explain me that.

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

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

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

def compute_bill(food):
total = 0
for key in food:
total += prices[key]

#2

You aren't computing any bills, so no list of food is required. To use your function, you would need to have a list of food.

#3

so when i write the same function in python on my computer, i would really need to setup a food list to make it working right?

well as i started this lesson, this really kept me thinking( and busy) outside of the instructions.

#4

If you want to run your function then that's because you have a food-list and want to know what the bill would be

If you want to run the function anyway, then you would need to create a dummy food-list to use as input

#5

ahh i see. this makes now sense!

#6

So where is the mistake?

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

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

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

def compute_bill(food):
total=0
for item in food:
total += prices[item]
print sum(food)

#7

you need to replace `food` with `shopping_list`
the `sum(food)` does work too, because the return will give you already the sum.

hope you have the correct Indentation.

#8

``````def compute_bill(shopping_list):
total=0
for key in food:
total += prices[key]

compute_bill(['apple']) resulted in a NameError: global name 'food' is not defined

#9

``````# Write your code below!
def compute_bill(shopping_list):
total=0
for key in shopping_list:
total += prices[key]