Stocking out - Correct results, but still not working


#1



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

Any guidance will be very much appreciated.

The code I am submitting gives me the right calculations in compute_bill and updates the stock, but I am still getting the same 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}

Why should the stock list look the same after we subtract one from the item's stock count?


def compute_bill(food):
    total = 0
    for fruit in food:
        if stock[fruit] > 0:
            total += prices[fruit]
            stock[fruit] = stock[fruit] -1
    return total

print compute_bill(shopping_list)
print stock


#2

Remove or comment out the last two lines. They will be added in the next lesson.


#3

Thank you, @mtf !!!
I am new to Python and I tend to over-think a bit.


#4

The exercises are generally basic and simple. For best results read and follow instructions closely. That way your work will meet the expectations. Happy coding!


#5

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