My code prints the item, price, and stock - why isn’t it accepted?

There is also a difference with the pages being loaded esp for this exercise there is a difference in the “instructions” section where its showing a preview of what the result should look like.

instruction-screen-1 instruction-screen-2

Same problem, although it looks like my instructions are different formatting:

Their solution is with each thing on a new line.

This question has surfaced many times in recent months. It would appear that there are two iterations of the same lesson, but written with slightly different instructions while using the same SCT (the old one). These instructions above cannot be followed.

Suggest structure your code to output,

price: ...
stock: ...

using three print statements.

@alyssavigil, may we call upon you once again to ask somebody in curriculum development to review this particular lesson and update the SCT to match the instructions?


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

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

for key in prices:
print str(key),
print “price: %s” % str(prices[key]),
print “stock: %s” % str(stock[key])


orange price: 1.5 stock: 32
pear price: 3 stock: 15
banana price: 4 stock: 6
apple price: 2 stock: 0

—But this is not accepted for some reason. Anyone know why?

Also did the shorter:

for key in prices:
print “%s price: %s stock: %s” % (str(key), str(prices[key]), str(stock[key]))

----Still did not work

Don’t use the str constructor in these lines. %s looks after that. key is already a string.

This may be late - howeve the instructions state " Print the answer in EXACTLY the following format:

apple price: 2 stock: 0" which tells me the output should be all on one line and not 3 separate lines per key

I also saw it in this format in Chrome on Ubuntu 18.04.

I’ve seen a lot of the material in the instructions tab displayed incorrectly.

1 Like

tried to do this lesson in this format, but Codecademy didn’t accept it as correct, however as you can see it follows the format correctly. I suppose there must be an error on this lesson that needs fixing, I guess everyone should just click solution to get around this for now.

My solution looks to be exactly like the format but not accepting.


"Print the answer in EXACTLY the following format: apple price: 2 stock: 0"

(One line per key != three lines per key)


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

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

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

THIS DOESN’T WORK: --> (despite being EXACTLY what is asked for)

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

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

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

#If the goal of the exercise is to purposefully stump us, please let us know somewhere ...
1 Like

The instructions do not correspond to the acceptable output. This has been reported numerous times. Python 2 is going to be officially obsolete in 2020, according to Guido himself, so perhaps the CodeAcademy mavens have decided to treat this course with benign neglect.

Until such time as someone decides to pay attention (or cancel the course), we’ll have to be content with knowing that we are not wrong, and move forward.

1 Like

It works, but not accepted why?

prices = { ‘banana’: 4, ‘apple’: 2, ‘orange’: 1.5, ‘pear’: 3}
stock = { ‘banana’: 6, ‘apple’: 0, ‘orange’: 32, ‘pear’: 15}
for key in prices:
print key + " prices: %s stock: %s" % (prices[key], stock[key])

prices = {“banana”: 4, “apple”: 2, “orange”: 1.5, “pear”: 3}
stock = {“banana”: 6, “apple”: 0, “orange”: 32, “pear”: 15}

for fruits in prices:
print “%s price: %s stock: %s” % (fruits, prices[fruits], stock[fruits])

Here is the code i entered, but is considered wrong … think there is a problem …

There may be two different versions of this exercise, and the SCT has not been modified to match the expectation of this version. Have you tried,

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

just to see if that might work?

1 Like

It works well ! Thanks for your help !!!

You’re welcome. Glad to see we have isolated the solution. The lesson either needs to be revised back to the old version, or the SCT needs to be brought in line with the instructions.

@alyssavigil, please point this to someone on the team. Thank you.

1 Like

Why isn’t my code accepted? I printed out exactly as asked using the string format specifier and converting all non-string into a string.
I also tried with float and int format specifier but those are rejected as well.

See the post three posts back up this page.

it doesnt work either

Funny, it worked for the previous poster. Try a reset then use the code and see what happens.