8. Keeping Track of the Produce



I get this error message , could someone explains to me the right code ?

Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)

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


They also want you to print the fruit name before the price and stock of it.
Like the example they gave you in the instructions:

price: 2
stock: 0

Hence you need three print statements.


and how can i do it ?
should i write the third print statement before the for loop ?


No, write it in the loop, just above the print statements for price and stock.
Output should look like this:

price: 1.5
stock: 32
price: 3
stock: 15
... #and so on

Looking at the prices dictionary, your fruits are the keys.


Quite common mistake in this lesson is that you need to print Key:

So should look something like this:

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

Also if you get error saying "Oops, try again. Check what your code prints for orange. It doesn't look quite right!"

make sure that you spell correctly, as if there is a mistake in word "price" or "stock" you will get this error. I found a mistake in printing word "prices", rather than price.


I got an error for this lesson too but I cant understand the error

my code >
for key in prices:
print key
print "prices: %s" % prices[key]
print "stock: %s" % stock[key]

after fixing code >

for key in prices:
print key
print "price: %s" % prices[key] # Notice that i only changed prices: to price:
print "stock: %s" % stock[key]

and it runs successfully , but why it is happening??


This is the output Codecademy wants...Notice how you did prices: in your first code instead of price:.


The codecademy system works just like a unix/linux system. Every output has to be typed exactly as they require it. Any deviation in spelling or format (alphabet case) will generate an error.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.