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


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