Stocking Out - Error


Working on SHOPPING TRIP: 12. Stocking out (

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
    return total
print compute_bill(shopping_list)


Hi @arrayblaster76510,

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.


Instead of

total = total + prices[number]


total += prices[number]


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


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

print compute_bill(shopping_list)

at the end of your code.


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.


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.


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.


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.


just comment it out compute_bill(shopping_list)


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.