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


#32

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


#33

i already answered this:

The lessons expects to see 3 print statements.


#34

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


#35

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


#36

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.


#37

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


#38

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


#39

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:


#40

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.


#41

So glad I came here-

I was trying to get it all on one line.


#42

The instruction tells me to print them inline.

The solution insists that it must be 3 separate lines.


#43

i printed in like c/a asked for it still does not pass 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 + ’ price:’ + ’ %s’ % prices[key] + ’ stock:’ + ’ %s’ % stock[key]


#44

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


#45

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

#46

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


#47

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

Their solution is with each thing on a new line.


#48

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,

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


#49

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

prints:

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


#50

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


#51

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