11 - Making a Purchase


#1

“compute_bill([‘apple’]) returned 10.5 instead of 2” How am I supposed to put it right?

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 computer_bill(food):
	total = 0
	for item in food:
		total += prices[food]
	return total

#2

Your function is named computer_bill instead of compute_bill.

Within the for loop, you have referenced food here where you should be referencing item

        total += prices[food]

#3

here:

total += prices[food]

food is a list, lists can’t be used to access dictionaries. That is why we have a loop, so we can get each item of food list and can add the price of item to total


#4

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