Making a Purchase


#1



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


Traceback (most recent call last):
File "python", line 25, in
File "python", line 21, in compute_bill
KeyError: 1


I'm stuck as I dont understand my mistake. Can you help me fix this?


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

n=[1,2,3,4,5]
print compute_bill(n)


#2

here:

print compute_bill(n)

when calling the function, supply shopping_list as argument, compute_bill is a function which calculates the bill from product (names) not numbers


#3

Aha! Got it. Thank you.


#4