# 12. Stocking out

#1

Hello Community, I am stuck on 12. Stocking out. I get the following 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}"

``````shopping_list = ["banana", "orange", "pear", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

price = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += price[item]
stock[item] -= 1
n = ["banana", "orange", "pear", "apple"]
print compute_bill(n)``````

#2

remove this lines:

``````n = ["banana", "orange", "pear", "apple"]
print compute_bill(n)``````

the function call changes the quantity, causing problems in the validitaion

#3

Thank you. It worked. Removing those two lines was the answer. For future clarity, what did adding those two lines do?

Did I "confuse" python/ my code by typing in
n = ["banana", "orange", "pear", "apple"]
print compute_bill(n)
??

What did python try to do with those two unnecessary lines? What made the code incorrect with those additional two lines?

Thank you!

#4

it didn't make the code incorrect, but by doing this, you called the function, which changed the stock, which means the validation can't be done right. (because of how the validation of codecademy works)

#5

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