Making a purchase


#1



I don't know where I made a mistake. Would appreciate any kind of help. Thank you in advance.


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


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


def compute_bill(food):
    total = 0
    for key in prices:
        if key == food:
            total = total + prices[food]
    return total

print compute_bill(shopping_list)


#2

An index must be a single item, not a list. Use key in place of food.


#3

Hey I tried it. It is showing the same error. Thank you though..


#4

This conditional is not needed.


#5

Yes sir, it helped. Thank you.

Also, there was another error in my code.

Error:
for key in prices:

Rectified:
for key in food:


#6

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