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


#1

Question

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

Answer

Codecademy checks for exactly the answer that it’s looking for in the instructions. This includes spelling, capitalization, spacing, and punctuation. If any of those are different, it’ll count it wrong.
The most common issue is printing prices: rather than price:, or capitalizing either word printed out.
Also, be sure to convert the value stored in the dictionaries to a string using the str() function so you can print it out!


FAQ: Learn Python: A Day at the Supermarket - Keeping Track of the Produce
#2

It prints identical to the solution command lines…?
I just did it slightly differently


#3

the exercise validates the presence of the 3 print keywords, which is why this isn’t working


#4

Oh, I get it. Thanks.


#5

I don’t understand this – in the case of prices you use price but where there is no s as in stock you simply use stock…very confusing


#6

Thanks for this! I had written for

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

and I couldn’t figure out why it was being rejected. You clarified it!


#7

Thanks to everyone who replied, i finally figured it out. thanks 5beatspersecond for the \n i realized what it does after playing around with it


#8
print "price: %s" % prices[number]

Your iterator variable is n, so that is the key you should be polling.


#9

Why is it printing out of order? Like shouldn’t banana be printed first, then apple, orange, etc.? It prints orange first, why is that?


#10

Plain objects are not ordered like indexed objects such as arrays. There is no record of the order of insertion so no predicting the order of output.