Making a Purchase


#1



https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/2/2?curriculum_id=4f89dab3d788890003000096

Traceback (most recent call last):
File "python", line 23, in
File "python", line 21, in compute_bill
TypeError: unhashable type: 'list'


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

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

# Write your code below!
def compute_bill(food):
    total=0
    for item in food:
        total=total+prices[food]
    return total
print compute_bill(shopping_list)


#2

inside the for loop, the food variable contains the list, the item variable contains a item in the list. you want to use to get the price of a item (prices[item]), you can't just get the price of the whole list in one go.


#3

you iterated over food and stored that in item, so you need to use prices[item]


#4

Thanks :slight_smile: