11. making a purchase


Still returns error:

Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5

This is my code:

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
        print compute_bill(shopping_list)

11 Making a Purchase

I think it's because you have the last line running in your loop. Take out the indents before

print compute_bill(shopping_list)

and shift it straight to the left margin. That should hopefully fix it.


You are absolutely right. I removed the indent and it worked. Thanks!


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