A bug in stocking out


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096#


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}


It should pass the test.
However if i initialize the stock again after calculation, it passes the test. This must be a bug.

print compute_bill(shopping_list)
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
print stock


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 item in food:
        if stock[item]>0:
           total += prices[item]
           stock[item] -=1
    return total

print compute_bill(shopping_list)
print stock


#2

Your code looks perfect, the only thing that looks different than mine is the end...
I didn't print anything, just defined the function and finished.
Your error message is telling you not to call compute_bill which you are doing...
I actually don't know why it's like this, but I was just letting you know how mine is different and I don't have any problems. :slight_smile:


#3

thank you very much. Now i understand that i put too much in script :slight_smile:


#4

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