11/13 making a purchase


#1

whats wrong here? get error saying " 'dict' object is not callable"
def compute_bill(food):
total = 0
for x in food:
total += prices(x)
return total


#2

For me this part of code seems fine. Can you paste whole code? After you paste it, select it and press Ctrl + Shift + C or use </> from the reply toolbar


#3
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

#4

Ok, turned out, that there is something wrong with this part

def compute_bill(food):
    total = 0
    for item in food:
        total += prices(item)
    return total

When using for with dictionaries it seems to be necessary, to use key. So, if you change item into key code should pass


#5

tried that out, works perfectly now thanks alot, also changed: total += prices(item), to be using [] instead of () so its now
total += prices[key]


#6

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total = total + prices[item]
stock[item] = stock[item] - 1
return total