Last active
December 20, 2015 23:58
-
-
Save stevencombs/6216143 to your computer and use it in GitHub Desktop.
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
# Print the total value of the fruit inventory | |
# A Codecademy Python (Something of Value) assignment | |
# Dr. Steven B. Combs, coding novice | |
total = 0 # Initialize variable to 0, required if code run more than once | |
for x in prices: # Step through each definintion in the prices and stock dictionaries | |
subtotal = prices[x] * stock[x] # Compute value of number of stock times individual cost | |
total += subtotal # Add the subtotal of each pair to the total (same as total=total+subtotal) | |
print total # Print the total | |
prices = { | |
"banana": 4, | |
"apple": 2, | |
"orange": 1.5, | |
"pear": 3 | |
} | |
stock = { | |
"banana": 6, | |
"apple": 0, | |
"orange": 32, | |
"pear": 15 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment