Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Created October 11, 2013 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencombs/6943034 to your computer and use it in GitHub Desktop.
Save stevencombs/6943034 to your computer and use it in GitHub Desktop.
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