A Day at the Supermarket trouble


Here is the code I have on something of value.
My problem is that the console doesn't print the right values.
I'm not sure what I am doing wrong here

"banana" : 4,
"apple"  : 2,
"orange" : 1.5,
"pear"   : 3,

stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15,

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]

total = 0
for key in prices:
print prices[key] * stock[key]



First of all
Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697


Show us the Instructions.....
Shouldn't you totalize the inventory.... instead of just printing the Value per Inventory-item...


Your first dictionary does not seem to be defined. It should read

prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3

Also, you do not need the last comma after "pear" : 3,
Although it shouldnt return an error, it is just not needed.


Also you have not calculated the total value of the stock and cost. You need to add the total of price*stock to the variable total and print it outside the loop.