11.Making a purchase(need help!)


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/making-a-purchase?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>
the errror message: “compute_bill([‘banana’, ‘apple’, ‘orange’, ‘pear’]) returned 4 instead of 10.5”

<What do you expect to happen instead?>
i expected to be correct and pass through the next step

```python

Replace this line with your 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 += prices[item]
return total

<do not remove the three backticks above>

#2

Hi @gregory1312,

The problem may be related to the indentation of your code. However, your posted code is not formatted, therefore we cannot see its indentation.

See How do I format code in my posts?.

Have you made sure that this statement is not part of the for loop …

    return total

#3

Thank you very much. The problem has been solved.


#4