Stocking Out ERROR - console thinks I am computing the bill when I am not


I am stuck for the stocking out problem. I think the code is right but when I try to run it it gives me the following error:

Oops, try again. calling compute_bill with a list containing 2 apples, 1 pear, 3 oranges and 7 bananas resulted in 35.5 instead of the correct 31.5

I made sure to "comment" the instruction compute_bill after I read in this blog that running it would change the stock before verifying the code! But I still get the error. Even if I erase the compute_bill instruction I get the same error. I tried refreshing the page and nothing works.
I will appreciate any insight and help.

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

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3

# Write your code below!
def compute_bill (food):
    total = 0
    for x in food:
        if stock[x] > 0:
            total += prices[x]
            stock[x] -= stock [x] - 1
    print total
    return total 

#compute_bill (shopping_list)



stock[x] -= stock [x] - 1

-= is a shorthand, so without shorthand this would be:

stock[x] = stock[x] - stock [x] - 1

that is a very rapid decrease in stock


Oh what a silly mistake!! Thanks a lot :slight_smile:


Silly mistakes are so easily made. Good you see where you went wrong and understand how to fix it :slight_smile:


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