12.Stocking Out


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

print compute_bill(shopping_list)

No Idea why this isn't working..........I keep getting the error,
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}

SOLVED, SEE REPLY


#2

So, it looks like i figured this out.

REMEMBER NOT TO CALL THE FUNCTION AT ALL PEOPLE! .......Very Frustrating.


#3

Hey, when stuff like this happens, remember to consider afterwards what you could have done differently with the information you had access to, to have dealt with it better. (In this case read the whole error message) That way, you come out of these frustrating situations with more experience, better equipped for next time.


#4

Hi, @chippro46125

Consider what @ionatan wrote, whenever you see a message. It is good advice. Evidently, the message you received has helped you fix the problem.

By now, you have removed the following statement ...

print compute_bill(shopping_list)

It is understandable that you would like to test your compute_bill function. You can restore that statement to your code in the final exercise, 13. Let's Check Out!, without any problem.