# Output is correct, but I keep on getting this message: compute_bill(['apple']) resulted in a TypeError: list indices must be integers, not str

#1

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

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

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

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

print compute_bill(prices)``````

#2

Hi I think that you don't need to call the function `compute_bill()`, in this lesson so try to remove it.

``print compute_bill(prices)``

#3

still got the same message

#4

``total += food[key]``

put

``total += prices[key]``

#5

okay, that solved the problem, thank you!!! but I'm confused, are we writing the function for any list? why are we hard coding the prices list?

#6

That was indeed confusing. They were asking us to use a list that wasn't part of the program instead of just using the directories we already made.

#7

Hi this part of the instruction

For each item in the `food list`, `add` the `price` of that `item to total.`

so with the `for loop` we go throught each item in the `food list` then we `add the price` of the item inisde the `total` and then we return it.

when you will cal the function `compute_bill()` with a `list of item` it will print the total of the price of all the item inside the list .

you could use the `shoppingg_list`.