11. I cannot understand, the problem

#1

I wonder, "shoppint_list" has only 3 item, "banana, orange, apple",
But the output of total, is the sum of prices's key.. (4+2+1.5+3) => 10.5

So I change the shopping_list , which is include only "banana"
But the result , total is still 10.5
I'm very confusing..

Pls, Anybody explain this code to me.

Thank you.

shopping_list = ["banana"]

shopping_list = ["banana", "orange", "apple","pear","mange"]

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 price in prices :
#total = total + stock[price] * prices[price]
total = total + prices[price]

print compute_bill(shopping_list)

#2

Using the list we created in Lesson 10, but adding a couple of strays, like the OP,

``groceries = ["banana", "orange", "apple", "mango", "pear"]``

It's important that we use the list we pass in as a parameter, `food`, in our function.

``def compute_bill(food):``

What we call the list is of no consequence, so long as we actually query it in the function. The parameter is how we do this.

``````    total = 0
for item in food:
total += prices[item]
``compute_bill(groceries)``