# Help With 10.A Day At The Supermarket

#1

Hello everybody, I'm having issues that I simply can't figure out... I appreciate the help.

The error I'm getting is:
"Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 8 instead of the correct 7"

The instructions say this:
Make the following changes to your compute_bill function:

While you loop through each item of food, only add the price of the item to total if the item's stock count is greater than zero.
If the item is in stock and after you add the price to the total, subtract one from the item's stock count.
This is my code, please tell me whats wrong.

``````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 > 0:
total += prices[item]

Thank You for the help!

#2

Not where we subtract.

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

#3

Here,

`if stock[item] > 0:`

After

`stock[item] -= 1`

to subtract one from the item's stock count.

And then you could `return total` on looping `for`

#4

I just tried it, This is the Error: calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 9 instead of the correct 7

#5

Never mind I Got IT! Thanks For The Help!

#6

I Got IT! Thanks For The Help!

#7

You're welcome.

Have fun coding!

#8

I deliberately didn't point out the 'other' mistake on the assumption that you would spot it from the clue I gave. Good work!

#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.