SOLVED - 10.11 Making a Purchase: TypeError 'str' object not callable


My code - found in the block below under # Write your code below! - throws the following error message:

Oops, try again. compute_bill(['apple']) resulted in a TypeError: 'str' object is not callable

I expect it to run the loop to return the sum of the prices. though I've tried changing the code, I haven't been able to interpret the error message correctly to find the right fix.

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 + item(prices)
    return total


Hi @alethinophidia,

Check this line for the problem ...

total = total + item(prices)

Consider what is the correct syntax for accessing one of the items in the prices dictionary ...

  • What is the key?
  • How should it be specified to access an item?


ahh, this syntax passed:

total = total + prices[item]

Thanks, @appylpye, those were good clues. I revisited the lessons below and it became clear:

1.) I was using parentheses rather than brackets, and
2.) I transposed the call command.

I was essentially using gibberish in trying to call keys inside a dictionary, but I'd flipped the dictionary inside out.

• Python Lists and Dictionaries.This Next Part is Key

• A Day at the Supermarket: This is KEY!