Hej.
Poniższy kod jest poprawny, ale nie wiem jak działa. Polecenia do tego zadania były:
Make the following changes to your compute_bill function:
*While you loop through each item of food, only add the price of the item to total if the item's stock count is greater than zero.
*If the item is in stock and after you add the price to the total, subtract one from the item's stock count.
Byłby mi ktoś w stanie wyjaśnić ostatni fragment kodu? Ten od def compute_bill(food). Nie rozumiem jak on działa.
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