Owning a supermarket is tough!


Hey guys! Hopefully most of you are having a better day than me. I have followed all the directions and once i finished my coding I got an error
(on the print "prices: %s" % prices[key]
`print "stock: %s" % stock[key]

nothing came up so i tried it with a different method to print the answers:

for key in prices:
print "prices" + str(len(prices)) + str(len(stock))
print prices
print stock
Sure it worked but the error message says:
Check what your code prints for orange. It doesn't look quite right!

If somebody could explain me this and perhaps give me a hint on how to do this correctly. I would appreciate it. Thank you guys.


Please provide a link to this exercise so we can be on the same page. Thank you.



you will probably have to login to open it.


You are on the right track in your other attempt, just not quite on target.

print "prices: %s" % str(prices[key])
print "stock: %s" % str(stock[key])

Edit: Remember to print the key, as instructed.


Hello, @user_beck!
You're not the only one who faced this kind of "error", quite a few other Codeacademics faced that too and the solution for it was to check if the format that's being shown to you at the instruction section of that lesson, refreshing and executing again or even change browsers.
There are moments that the program used to compile and execute our codes glitches or something like that.

Best regards,


@mtf: I didn't use the function str() to convert it and it worked as well, I can show you the screenshot if you want.


Yes, I was just going to bring that up. It matters not which form we use. The OP is nearly correct but for one tiny detail...

price: 2
stock: 0

The instructions ask for this style of output. Notice the label on the second line?

However, from a pureness standpoint it makes sense to convert data to string if we are using a string format.


I tried your method "prices: %s" % str(prices[key])"
it worked but i still got an error message
Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!
also it prints out the value but not the key.
prices: 1.5
stock: 32

what its asking me to do is
prices: orange: 1.5
stock: orange: 32

at least thats my understanding of the directions.


Check the example in instruction #2. Change prices: to price: and see what happens.

The output should look like this for orange:

price: 1.5
stock: 32


Continuing the discussion from Owning a supermarket is tough!:
So staid up till 4AM last night and continued this morning and finally figured out. I played around with the key and value placement in the code also I included print apple in order to get the syntax form described in the example 2.
here is my code:
price = {"banana": 4, "apple": 2, "orange": 1.5,"pear": 3}
stock = {"banana": 6,"apple": 0,"orange": 32,"pear": 15}
for value in price:
print "price: %s" % price[key]
print "stock: %s" % stock[key]
print 'apple'

One more thing. I ended up not converting the data into string at all. Anyway thank you guys for the help.

Another thing. I went back and changed for value in price: to for key in price and that worked so i guess I didnt have to change key with value.


for value in price:    
    print "price: %s" % price[key]    
    print "stock: %s" % stock[key]    
    print 'apple

In this case you'd be printing the value in the entry key everytime you loop through it in each entry of the dictionary you're using to iterate but such variable wasn't created nor has anything in it, at least not where you posted your code.
You're supposed to using the variable you are using to iterate through the dictionary prices, which is value, between the brackets to print the value stored at the dictionaries price and stock where the value is equal to a certain value entry (right element of the dictionary entry).

Hope I was clear, if not I'll try to explain in a different way.


I think I understand what you're saying but in the next exercise I was asked to find out the total cost of all the variables stored in the dictionary so i had to multiply all the values not the key's. I tried doing
print prices[value] * stock[value] and an error came up stating that name 'value' is not defined. Any suggestions?
here is the link to that post http://discuss.codecademy.com/t/confused/24849?u=user_beck if you have the time i would appreciate it if you would take a look. Thank you so much.


@user_beck: @mtf answered at your newest topic. Follow his instructions and your code will work.