# A Day at the Supermarket: Why is this not working?

why is this not working?
why does it calculate wrong?

Please post the code that creates your `stock` and `prices` dictionaries.

Did you change any of the values in the `stock` dictionary? It should contain â€¦

``````    "banana": 6,
``````

I didnâ€™t change. it was identical to the previous exercise.

the only difference is in lines 22,23. In the solution it appeared:
total += price[item]
stock -= 1

I believe what @appylpye means is that they would need to be able to reproduce it in order to have a chance at figuring out whatâ€™s wrong.

I canâ€™t spot it from what youâ€™ve said, which makes me think the problem isnâ€™t in what youâ€™re showing, itâ€™s somewhere else, and being able to reproduce it makes it much much easier to start narrowing down what it could possibly be.

It could very well be in what youâ€™re showing, but I donâ€™t want to look too hard without knowing that it is the case (which reproducing it could show me)

1 Like

here is the full code

That requires an image-to-text conversion program.

1 Like

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 = toal + prices[item]
stock[item] = stock[item] - 1

print compute_bill(shopping_list)
``````

What is the variable `toal` doing here?

``````      total = toal + prices[item]
``````
1 Like

Still one missing piece.
Which exercise?
Some digging tells me:
That code passes there. Canâ€™t reproduce.

One explanation for the error message is that stock wasnâ€™t checked (like in the code of previous exercise).
Maybe that is the right exercise (itâ€™s the only one with that particular error message in it), but some other code than was shown was used, at least from the exercise testâ€™s perspective

Yes, the original `compute_bill` function looks fine, so the problem must have been elsewhere. But now, in the most recently posted version of the function, we have this variable `toal`.

Since the code has been modified several times since the original post, which did not show all the code, we may no longer be able to identify the original problem.

i guess it was just that typoâ€¦ the following code (identical to the first one but no typo) gave me the result of 5.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]
stock[item] = stock[item] - 1

print compute_bill(shopping_list)

Itâ€™s not that typo. Your first picture doesnâ€™t have it.

I think the code for the previous exercise is being used. Whether thatâ€™s codecademy or you mixing them up I canâ€™t tell. Iâ€™d refresh the page, and if that doesnâ€™t help, reset the exercise (help button in the corner)

Oh and keep in mind that practically all forums apply formatting to posts. (Try coping from your post, wonâ€™t work, itâ€™s not an exact copy)

I refreshed and copied this code again (notice the bold area) and it works. i dont know wht didnt it work the first time (same 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 item in food:
if stock[item] > 0:
total = total + prices[item]
stock[item] = stock[item] - 1
â€¦ suggests that for the exercise that you were doing, your original code managed to sell 9 bananas, when there should have been only 6 bananas in `stock`. We may no longer be able to determine how that happened.