# Stocking Out - Error

#1

Working on SHOPPING TRIP: 12. Stocking out (https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096#)

Keeps giving the error message "Oops, try again. Stock doesn't look quite right! Make sure to not call compute_bill
since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}"

No matter how I look at the code, I think it should run the way it is supposed to, yet output is constantly "5.5" Please advise.

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

print compute_bill(shopping_list)``````

#2

Codecademy does not want you to do this yet ...

``print compute_bill(shopping_list)``

You can do that in the next exercise, if you want.

#3

`total = total + prices[number]`

try:

`total += prices[number]`

#4

Thank you. I tried that, but it returned an error to me. So that is why I used total = total + prices[number] instead

#5

It should still work, so long as you don't include

``print compute_bill(shopping_list)``

at the end of your code.

#6

Thank you so much. It worked after that. Can you please advise as to how I am supposed to tell until where my code should run? It would be a great help as I have been stuck on some exercises for a while and it is all because I printed when not supposed to.

#7

If the instructions say to print something, then print it. If they don't say to print something, then don't print it (unless of course you are debugging). Not really much to it.

#8

In some exercises Codecademy allows you call functions that you have written, even when it did not ask you to do it. In this exercise, it is stricter about that.

#9

In other words, unless you feel like testing codecademy's patience stick to what the instructions tell you to do. After you complete the exercise you can go back and mess around with the code if you want later.

#10

just comment it out compute_bill(shopping_list)

#11

You'd have to also comment out the `print` part of that line as well, else, you'd get a syntax error. But, yes commenting out unnecessary code is an alternative to just deleting it altogether.

#12