8. Keeping Track of the Produce


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3?curriculum_id=4f89dab3d788890003000096

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]


#2

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:

apple
price: 2
stock: 0

Hence you need three print statements.


#3

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


#4

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

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

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


#5

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.


#6

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??


#7

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


#8

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.


#9

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