Really don't see whats wrong with my code. When I run the example they give on my python, it prints the total of the numbers in the n list. But when I go to print compute_bill(shopping_list), it only prints the first item price not the total of all items


#1

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 += prices[item]
	return total

this is the code I'm using. when i run the code it says
"Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5"
it returns the value of banana instead of the total value of all the items in the list added up. i don't understand how you make all the items in the list add up


#2

For this lesson, #11, we don't print anything.

We cannot tell if your indentation is correct since you did not format your post. Please learn how to do this so your code displays correctly.

Hint: on a blank line, type in three back-ticks

```

and Enter, then paste in your code, then Enter again and type in three more back-ticks,

```

#3

Hard to tell without correct indention of the code. I'm guessing that it might be something wrong with the indention if you just get the first value added to 'total'..


#5

Back off the indentation on the return statement by 4 spaces. (thanks for formatting, btw, but you should have left the rest of the code that was there, all the same.)


#6

that makes it line up with def @mtf


#7

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

is how I'm seeing it. Should be,

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

four spaces indent from left edge.


#8

When indentation problems occur, we are often forced to go through our entire code and replace any tabs with 4 spaces, just to get everything matched up. It's a royal pain, and wish we had a tool for tidying our code to unify the indentation character.


#9

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

just make a call for function

compute_bill(shopping_list)