# Stocking Out

#1

I'm not sure what is the error. Can someone help me?

My result is different than what it should be.
i.e. 1 Apple, 3 Pears, 1 Orange and 9 Bananas results in 46.5 instead of 34.5.

``````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 = total + prices[item]
elif stock[item] == total:
count = stock[item] - 1

#2

Do you agree with the error message?

If so, execute your function manually or add prints in it saying what it does, compare to what it should do.

If not, then out of that there are 3 pears, 1 orange, and 6 bananas available to purchase which adds up to 34.5

#3

hi there, you could try mine.
def compute_bill(food):
total = 0
for item in food:
if (stock[item] > 0):
total = prices[item] + total
stock[item] = stock[item] - 1

#4

This should work

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

#5

It doesn't work. I have almost exact same code as yours and exact same problem as the author of this topic.

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