If you think you’ve coded your function properly and are receiving an error message along the lines of stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock!, this is because in this step we aren’t using the function after writing it, we’re just writing the function.
Try deleting where you used the function and then Run your code again.
It’s great to want to test your code! However, Codecademy runs tests to check your code that depend on the values being the original values, and running the function in your code in this step changes those values. You’ll be able to use it in the very next step!
I’m not sure if this solves your problem, but try indent the stock[item] -= 1 more.
It seems to me that currently it sits on the same level as the ‘for loop’ (i.e under the main function level) but it should be under the ‘for loop’ since we need to do that subtraction in each loop.
I guess you wanted to write …the item is in stock…
anyway, it is strange because that’s what I thought at first but putting that line inside the if clause caused an indent error. So I went ahead and tried other indents. And strangely only the above mentioned (by me) worked.
today I went back and tried your suggestion again, and it worked now. pretty odd.
maybe it has something to do with tab vs space indentation?
I’ve been experiencing many IndentationError messages (in this as well as previous exercises) despite my code being identical to the solution and Codecademy wouldn’t allow me to move on unless I went for the Solution. I even tried deleting the indents of the error Line and reintroducing them in a consistent manner, but it still wouldn’t accept my code. Is there another solution? Do I need to delete all indents of every line and consistently reintroduce them line by line for my code to be recognized?
codecademy’s editor sucks when it comes to indent. I would re-indent the code in your own local editor, if you haven’t set this up, you could use sites like repl.it
def compute_bill(food):
total = 0
for items in food:
if stock[items] > 0:
total += prices[items]
stock[items] -= 1
return total
print compute_bill(shopping_list)