Not understood how stocking out code works


can someone help me to understand how the below code works

Replace this line with your code. 
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 item in food:
        if stock[item]>0:
    return total


what do you understand already? It is easier to explain something if you know what some knows (or doesn't know)


I know the code till last second statement I don't know how last statement works


which one? this one:


using references words is vague.

well stock is a dictionary containing your products (dictionary keys) and how much there is left in stock (values of key), item is your loop iterator which contains your products the consumer wants to buy, you use this key to access the dictionary and reduce the value by one


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