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


Why wouldn’t this work?
I’m pretty sure it prints out the same format that it asks for…


i already answered this:

The lessons expects to see 3 print statements.


Why should we format the values of key as strings (%s) while these values are integers ?


Please it seems that my code is correct but it stays to the red


for each key (product) print out the key (product) along with its price and stock information

you only print out apple, not all products as required by the exercise.


I had already done that. It was the first code that I had written. This is it


even though the required format displays as
apple price: 2 stock: 0
it’s actually looking for
price: 2
stock: 0
Are you viewing through firefox? As I was and got that display too


The wrong check in this exercise! It is said to print the answer in EXACTLY the following format:

apple price: 2 stock: 0

But it still checks for 3 prints in solution :triumph::rage::face_with_symbols_over_mouth:


I had the same problem, beleberder. My output was exactly as requested and I even used the % syntax it wanted.

for food in prices:
  print str(food) + " price: %s " % str(prices[food]) + "stock: %s" % str(stock[food])

All I could do was ask for the solution.


So glad I came here-

I was trying to get it all on one line.


The instruction tells me to print them inline.

The solution insists that it must be 3 separate lines.


i printed in like c/a asked for it still does not pass prices={
“banana”: 4,
“apple”: 2,
“orange”: 1.5,
“pear”: 3
“banana”: 6,
“apple”: 0,
“orange”: 32,
“pear”: 15
for key in prices:
print key + ’ price:’ + ’ %s’ % prices[key] + ’ stock:’ + ’ %s’ % stock[key]


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

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

for n in prices:
print n
print “price: %s” % prices[n]
print “stock: %s” % stock[n]

my code is running well but codecademy is showing wrong


I believe that this piece of code should be accepted, but it is not:

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])


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