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


#1



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(food)
    return total


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

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


#2

here:

total+=prices(food)

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


#4

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]

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


#5

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


#7

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