# Making a purchase 11/13 Help!

#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
}

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

here is my code. However I get this error: Oops, try again. compute_bill(['banana', 'apple', 'orange', 'pear']) returned 4 instead of 10.5

I really don't know whats wrong.

#2

I think there is a indent problem

(0 indent)def compute_bill(food):
(1 indent)total = 0
(1 indent)for key in food:
(2 indent) total+=prices[key]

#3

I was struggling with this too and finally got it to work with this 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}

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

#4

Thank you for this. The wording for the problem was a bit vague, but I'm glad I very close to the answer.

#5

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

I copied your code almost exactly, but it didn't work for me? it says it gets zero instead of two.

#6

I ran your code through and it worked fine. It looks like it was just an indentation problem.
Make sure it looks like this:

``````def compute_bill(food):
total = 0
for x in food:
total += prices[x]

0 indent
1 indent
1 indent
2 indents
1 indent

#7

I try this and it work:

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

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