Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Last active December 20, 2015 23:58
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/6216143 to your computer and use it in GitHub Desktop.
Save stevencombs/6216143 to your computer and use it in GitHub Desktop.
# 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