Making a Purchase



Despite the fact that the result is correct ($72) I receive the following error message:

Oops, try again.
compute_bill(['apple']) returned 0 instead of 2

def compute_bill(food):
    total = 0
    for item in food:
        total += stock[item] * prices[item]
    return total 
print compute_bill(shopping_list)

What am I doing wrong? Thanks!


Why do you need

to be part of the total?


Thanks for your prompt response Kyleaw!

I assumed that I had to calculate the total cost of the stock ($72) and not
the unitary prices only.

Per your remark, I eliminated the stock[item] from the expression and now I
can proudly go to the next lesson :grin:


Do not be burdened by your pride.

Go forward on the merits that got you this far.


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