10.11 Making a Purchase - Type Error, dictionary object not callable


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):
    for item in food:
    return total

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





prices is a dictionary, a dictionary is not callable (functions are callable, dictionaries are not)


Ok. Both responses are much appreciated!
I was curious how my code here differed from the previous exercise...

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]

for fruit in prices:
produce_value = prices[fruit]*stock[fruit]
print produce_value
print total


compute_bill calculates the bill for a customer who buys items (which we represent with a list)

from the previous exercise, you calculate how much the entire stock cost


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