Making a Purchase


#1

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

Hi,

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!


#2

Why do you need

to be part of the total?


#3

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:


#4

Do not be burdened by your pride.

Go forward on the merits that got you this far.


#5

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