Making a purchase


The error menssage
"Oops, try again. compute_bill(['apple']) resulted in a TypeError: list indices must be integers, not str"

the code

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):
"""iterations start"""    total=0 
    for item in food:
        total = total + food[item] """iterations ending"""
    return total
#i don't know why iteration are not appearing here in Q&A, but ok

Making a purchase

I'm guessing you should really be accessing the prices dictionary, not the food list.
Lists require that you access indexes using an int, unlike dictionaries.

Try this instead:
total = total + prices[item]


thanks! I found the answer before you tell me, but thanks anyway.