Issue with <stocking out> part.12


I have no idea about the mistake I made in this practice.
Could anyone help me have a look in it?

I got error like "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", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
def compute_bill(food):
    for item in food:
        if stock[item] > 0:
            total = total + prices[item]
    return total
print compute_bill(shopping_list)


Remove the if statement,

and this decrementation,


if you remove that statement, you don't check for available stock
if you remove the "decrementation", the stock doesn't leave the shelf...

so, we'd be exactly back to where we started with the previous code...


the answer is actually in the error message:

Make sure to not call compute_bill

yet you call compute bill, which will change the stock.


Hello @stetim94.
Could you explain more about where did i call compute_bill?

The first and only time i called compute_bill in my code is the last line while printing it out. Then how do it affect the stock?

Thanks for your assistance and time :slight_smile:


this is the function call:

print compute_bill(shopping_list)

well, calling the function causes the function to execute, reducing the stock:


before the exercise code can be validated, the error message says so as well


I didn't call any function and mine code is showing not giving correct figure 7


if you have a question, go here, make a new topic, with this little info its really difficult to help you


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