A Day at the Supermarket
Stocking Out

Now you need your compute_bill function to take the stock/inventory of a particular item into account when computing the cost.

Ultimately, if an item isn’t in stock, then it shouldn’t be included in the total. You can’t buy or sell what you don’t have!



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.

Folder Icon

Take this course for free

Already have an account?