# 12/13 I've checked and doublechecked this code and can't get it to work :(

#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 item in food:
if stock[item] > 0:
total += prices[item]
stock[item] -1

I get the error message "Oops, try again. calling compute_bill with a list containing 1 apple, 2 pears, 3 oranges and 9 bananas resulted in 46.5 instead of the correct 34.5"

#3

I’m not 100 percent sure why your code doesn’t work, but if it still isn’t working, you could try this:

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total = total + prices[item]
stock[item] = stock [item] - 1
else:
False

you’ll want to indent it
if you’ve solved it already (this is pretty old), you can ignore this

#4

There seems to be a bug in this CodeAcademy lesson, I run this code from a comand line on my computer and the output is correct. Somehow I am missing something.

#!/usr/bin/env python
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 fd in food:
if stock[fd] > 0:
total = (prices[fd] * 1) + total
stock[fd] -= 1
else:
False

print “Shopping Total %s” % compute_bill([“banana”])
print “Stock %s” % stock

#5

are you indenting the code correctly?

#6

This is my version of code. I posted it below. I think the problem is not very intuitive, but used the hint.

def compute_bill(food):

``````total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] -= 1