How to use the Stocking Out code


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


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


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