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.


#11

Following your explanation, it would then seem that there’s a bug if Codecademy can’t recognize the code in the below image as being a correct solution and also fails to display any error message?

The only difference is in the variable name, but the instructions didn’t specify a variable name to use for the for loop.

Edit: I even tried to copy the code from the Solution given and pasting it after resetting the exercise, and Codecademy still doesn’t recognize it. It seems that the only way to move on from this exercise is to click on “Solution” for the “Next” button to light up.


#12

Same here. The only way out is asking for the solution.

My solution:

Codecademy solution:


#13

Hello everyone.

I can’t understand why i dont get the ok with my code on the same lesson. And i don’t understand the answers on this topic about why my code isn’t be accepted by the editor.

On lesson 7 “Investing in stock”, this was my code answer :

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
print “price: %s” % prices[key]
print “stock: %s” % stock [key]

wich print

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

Why this is wrong? i print, name, price and stock. In correct the order.

Bye and thanks for answer


#14

Your code is correct. I had the same issue yesterday. The only way I found to move forward was by clicking on the “Solution” button and then “Next”.


#15

Nice to know im not the only one with the problem haha!. Lets hope someone with more experience see this thread.


#16


Same issue here. Followed every hint, converted numbers into string for print to display it without any issues, but CC won’t let it go through, nor does it display any error message.
I guess for non Pro Codecademy users, we’re stuck. Regardless of pressing the Solution button, as all it does is show a popup that gets me back to where I was. I wish someone would come up with a solution :-/


#17

Maybe try reporting it as a bug? (in the left panel, all the way at the bottom, below the Instructions)
For me and seemingly some other users, pressing the “Solution” button actually enables the “Next” button, and for one I’m not a Pro user, so there must be something wrong with your CC.


#18

I’m not a “pro” user either. Try to reload the page and see what happens, I’ve to do this time to time and it works.


#20

had the same problem, answer looks good but not accepted


#21

Dictionaries don’t print in a specific order. Not sure why, however.