Help Me Identify the mistake


A Day at the Supermarket
12. Stocking Out

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}

I get this error message whereas I believe the code is correct(there is a comment in the end #for checking)

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

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

#for checking
for x in stock:
    print ("%s %d")%(x,stock[x])


remove this line:

print compute_bill(shopping_list)

it will execute the function which will change the stock


yeah..removing the code actually solves the problem but in the code compute_bill is not called and the logic asked in the question is in the compute_bill() function
link :


yes, but if the function is called, the stock changes, which makes validating really difficult because you don't know what the stock is

so you can have the function call until you reached the right code, then you temporary have to remove it to get pass the exercise


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