Making a Purchase error code dict is not callable?


I keep getting the error message . "Oops, try again. compute_bill(['apple']) resulted in a TypeError: 'dict' object is not callable"

Any ideas why this might be happening? I've compared my code to a bunch of other corrected responses on this question and I'm just not seeing where mine is going 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

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


Oh my gosh. I looked at other code for like 2 hours, posted and immediately saw what was going wrong. I used parenthesis instead of brackets for accessing the prices list. I wrote prices(item) where it should have been price[item]


This code:


looks like a function call, this is the reason of the error.

To retrieve data from dictionary you have to use:



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.