11. Making a purchase



When i run the code it gives an error message, "Oops, try again. compute_bill(['apple']) returned 0 instead of 2"

I suspect it is trying to run the function against the stock dictionary, but I'm not really sure why.

shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3

def compute_bill(food):
    for item in food:
        total + (prices[item])
    return total



Do you find something weird here? You haven't assigned a variable to the loop.

for item in food:
        total + (prices[item])

It should be something like this:
total = total + prices[item]

Happy coding :slight_smile:



I would suggest that you look at lesson 8 - keeping track of produce.
Look at the 'for' section and your 'for' section.
Also look at the example in this lesson's calculation, you are missing something.

Hope that helps.


yaa i did the same thing but it still doesnt work. its showing error. can someone please send the correct solution


asking for answers/posting answers without explanation is not according to the guidelines, please make a new topic with your (formatted) code + error message so someone can help you.


Try removing the parenthesis, and adding in the += instead.


you're not adding anything to total. it runs apple and see
but thats all. try
total = total + prices[item]


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