Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a compute_bill function to take the stock/inventory of a particular item into account when computing the cost. If an item isn't in stock, then it is not included in the total.
# Computer the bill for a shopping list
# A Codecademy Python (Stocking Out) assignment
# Dr. Steven B. Combs, coding novice
shopping_list = ["banana", "orange", "apple", "orange", "apple"]
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
def compute_bill(cart):
total = 0
for item in cart:
if stock[item] > 0:
total += prices[item]
stock[item] -= 1
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.