# Help Me:A Day at the Supermarket Making a Purchase

#1

Define a function compute_bill that takes one argument food as input.

In the function, create a variable total with an initial value of zero.

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

Finally, return the total.

Ignore whether or not the item you’re billing for is in stock.Note that your function should work for any food list.

i don’t know where i wrong?

``````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+= key
print (compute_bill(shopping_list))
``````

Thanksyou.

#2

``````def compute_bill (food):
total = 0
for key in food:
print key
total+= key
print (compute_bill(shopping_list))
``````

we can see `key` are the products (banana, orange and so on)

but we need to add the price to total, maybe we can use our prices dictionary somehow?

#3

compute_bill([‘apple’]) resulted in a TypeError: list indices must be integers, not str

#4

i know what the error message is, not important. Did you add the print statement i showed you? Then you see `key` is a product of type string, string + integer isn’t good. You need to get the price of item and add it total

If you need more help, post an updated version of your code

#5

we have our `prices` dictionary, and `key` (which contains our items/products) so we can use `key` as key to get the price value from dictionary