How to use the Stocking Out code


#1



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


How to use this code?
Do I have to create a list for food?
For example food = ["apple", "eggs", "orange"]


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


#2

Well, you have your shopping_list to use as test, right?
You just call your compute_bill function with shopping_list as the input.


#3

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