Created
October 11, 2013 22:31
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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