This forum is now read-only. Please use our new forums! Go to forums
[fix] Oops, try again. Check what your code prints for orange
This is a commonly asked question, so here is what that error message means:
the exercise demands that what you print is in a certain format
each character that is printed out has to be exactly right
spaces may not be added or removed
“price” may not be changed to “prices”, because a fruit does not have multiple prices and so english grammar dictates that it should spell “price”
the capitalization style has to be the same (all lower case)
THIS IS CORRECT:
apple
price: 2
stock: 0
the two most common incorrect variations of this that i see are:
WRONG:
apple
prices: 2
stock: 0
this version says prices with an s at the end of price, a fruit only has a single price, so your output should reflect this!
the second is getting the capitalization wrong:
WRONG:
apple
Price: 2
Stock: 0
p and P are different characters, so “Price” and “price” are different strings
on the off-chance that you got this error even though your format matches the first example in this post, then you most likely got the values wrong, double check the math!
Answer 548fc962e39efe929d00089f
Answer 556eea339113cba68d000652
Was having problem with this exercise as well, later on I figured out that the reason why It kept throwing errors even though the output looked correct for me was that the string in my print statements needs to be EXACTLY same as in the example.
for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
notice the lowercase p the colon position and space in “price: %s” string. This code has worked for me. Yes it might sound stupid to you, but the thing which evaluates your code is simply a machine. And as such it simply follows orders EXACTLY as it was programmed to, it’s not capable of “thinking outside the box”
12 comments
Thanks
Thanks a lot!
awesome thank u
thx
thx i still cant figure out why my code is wrong, it looks exactly the same
thx
Thank you
same thing happened here. Be sure to write “ print: “price: %s” not prices
thank you
Solution worked for me - thanks for sharing
thx
worked! thx. it’s about colons space
Answer 54d437ea86f5521c5d000ee9
Don’t write Price
instead of price
and Stock
instead of stock
.
3 comments
This.
thanks, it helps a lot
THIS! Thank you!
Answer 54a0674d9113cbc7e301334c
In my case, I had an additional space beside %s ie: print “price: %s “ % prices[key] #note the additional space here print “stock: %s” % stock[key]
instead of
print “price: %s” % prices[key] print “stock: %s” % stock[key]
Even a tiny space counts!
9 comments
I was pulling my hair out till i realized that I had and additional space as well….
..same here :)
mine still doesn’t work:(
Not working :(
exactly..thank you. same space/ was there dude
I forgot the : deep sigh
Thanks a lot.
Yeah…Space really counts…Thanks a lot!
Thank you… I too had the same problem…
Answer 549a87709113cb428d00afaa
Hey Jonatan, why would it be wrong if we wrote %d instead of %s because after all the value corresponding to the key is a decimal input and not a string.
4 comments
yeah it would give 1 instead of 1.5 for stock value of orange.
%d is for decimal integer, %f is float, %s will do the job most of the time since that’s just the default string conversion so.. try %s, and if you needed something else than what that gets you then go google python string formatting
Thank you!!!!!!
%r also worked for me.
Answer 549fef0ed3292f9d52012143
Hi Vic, Thanks for your post. I’ll bet if you change your string print out to all lower case, it will work. (It did for me.) Best, Wim
1 comments
Oh sorry I did not see this:_(
Answer 54a965d4d3292f49b0007388
I think the interpreter requires us to follow the instructions exactly. We’re required to “print the answer in the following format”: apple price: 2 stock: 0
Notice “price” and “stock” are in lowercase. I was only rewarded with “Way to go!” when I printed them in lowercase.
Answer 54fcd15ae39efef98e002997
The problem is syntax, but not in the code: it’s in the directions. The directions offer you the opportunity to use the “%s” in your code, when in actuality YOU MUST USE THIS FORMAT.
I’ve seen it in other instructions, where it says you CAN do something a certain way, when you are actually required to do it that way.
1 comments
Additionally, in exercise 6/13 you are instructed to use “prices” but here you are told “prices” doesn’t work because “a fruit does not have multiple prices and so english grammar dictates that it should spell “price”.”
Answer 5504d96e51b8875d2a005586
Thank you so much! Wish I could upvote your answer!! My error was capitalizing “Prices” in the output
Answer 552b802795e378b6b3000263
I did: print i print “price: “, prices[i] print “stock: “, stock[i]
This produces identical output to what passes but was still failed until I coded with %s.
I assume the code is checked as well as the output.
Answer 5560b8dd9113cb0297000100
I´ve noticed that if you add one more print statement: for key in prices:
print key print “price: %s” % prices[key] print “stock: %s” % stock[key]
the code is displayed separated with spaces between the fruits: pear price: 3 stock: 15
banana price: 4 stock: 6
But, if you do not write that extra print statement, the code is displayed without the spaces: orange price: 1.5 stock: 32 pear price: 3 stock: 15
whats my point? well, i dont know why Python do that… Anyway the code is right in both cases.-
Answer 559d1039d3292ffba300067f
prices = { ‘banana’ : 4, ‘apple’ : 2, ‘orange’ : 1.5, ‘pear’ : 3 }
stock = { ‘banana’ : 6, ‘apple’ : 0, ‘orange’ : 32, ‘pear’ : 15 }
for fruit in prices: print fruit print “price: %s” % prices[fruit] print “stock: %s” % stock[fruit]
2 comments
It is wrong…
yeah its wrong please remove comment
Answer 55a10d299376761c8d0003bf
I was also stuck in this confusion but here is that code which works for me
for key in prices: print key print “price: %s” % prices[key] print “stock: %s” % stock[key]
the problem is the space between price and colon and stock and colon
Answer 55f454b6e39efe454c0005e9
If the old-school %s string formatting is confusing, you can use the more modern approach, which is .format, like this:
for key in prices:
print key
print 'price: {price}'.format(price=prices[key])
print 'stock: {stock}'.format(stock=stock[key])
This works in the code checker and makes it much nicer to read, which is why people use this more and more. Even python’s own documentation recommends that you use .format unless the code you’re working in already uses the old C-style string formatters.
FWIW, future versions of python will have string interpolation like ruby (PEP 498 was recently approved), so eventually all of this confusion will no longer be an issue.
Answer 548f71d295e378218500002f
2 comments
check for extra spaces i.e.: print “price: %s “ –> this will also generate the same (and totally unrelated) error driving you crazy for a few minutes…
It’s especially maddening when the instructions use prices…
Answer 5490699795e378eb9f001e29
Surely the example text is wrong then?
print “Once: %s” % once[key] print “Twice: %s” % twice[key]
1 comments
it just doesn’t have the first line “print key”
Answer 549e462376b8fef01500f9f5
The Codeacademy website has a bug. Here is the program I’m entering:
prices = { ‘banana’: 4, ‘apple’: 3, ‘orange’: 1.5, ‘pear’: 5 }
stock = { ‘banana’: 6, ‘apple’: 0, ‘orange’: 10, ‘pear’: 1 }
for key in prices: print key print “Price: %f” % prices[key] print “Stock: %s” % stock[key]
Here is the output:
orange Price: 1.500000 Stock: 10 pear Price: 5.000000 Stock: 1 banana Price: 4.000000 Stock: 6 apple Price: 3.000000 Stock: 0 None
That output is correct, yet I’m still getting this error message:
“Oops, try again. Check what your code prints for orange. It doesn’t look quite right!”
6 comments
I guess the error is because it wants the orange’s price to be in float and the rest to be in integer. It is best to use %s instead of %f
Also, I think that you may have the wrong stock numbers.
just put the %s format specifier and take care of spaces you add.
This is definitely a bug on their site. Here’s my original code that gave the “orange” error followed by the correct code:
for x in prices: print x print “Price: %s” % prices[x] print “Stock: %s” % stock[x]
for x in prices: print x print “price: %s” % prices[x] print “stock: %s” % stock[x]
So what cleared the error was lower casing price and stock within the quotes. This is a bug because it errors if these two words are anything but lower cased price and stock. It of course shouldn’t matter whatsoever what words in quotes here are.
Another bug. This site cleared my formatting. I’m on Mac 10.9.5 on latest chrome
you put print “Price: %f” % prices[key] instead of print “price: %s” % prices[key] the difference is the %f and %s
Answer 549e46d486f552877c00ef60
Sorry the printing loop should be:
for key in prices: print key print “Price: %f” % prices[key] print “Stock: %s” % stock[key]
But I’m still getting the error message.
8 comments
you need to lower case Price and Stock
中文 Chinese
Ok so…..what is the relevance of Chinese? Lol
maybe its cuz your putting price and stock in upper case instead of lower case vic. Hope that helps
Yes this was my issue, didnt think the string would matter upper or lowercase
maybe it’s the f after the %sign after print “Price”
use lower case letters like “price”,”stock” or the interpreter will throw an error
you should leave it only like print “Price: %s “ % prices[key] hope this helps print “Stock: %s” % stock[key]
Answer 54ca12ea95e37824440014df
1 comments
yep
Answer 54ce91c276b8fe8698004562
Answer 54d3019086f5523d78001c8c
oh,This is the reason that stops me. So, like this is correct: for key in prices: print key print “price: %s” % prices[key] print “stock: %s” % stock[key]
this is wrong(prices just more than price a character “s”): for key in prices: print key print “prices: %s” % prices[key] print “stock: %s” % stock[key]
Answer 54d8b53286f5523b88009349
Answer 54e5dbe0e39efe4cc70016b9
Answer 54f712409376763ced001de7
This error of orange my god has got me so high.
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]
There isn’t any error in this code but still it was giving that stupido orange error.
but then putting just a space in two print statement it gives o/p with green signal.
for ja in prices: print ja print “price: %s”% prices[ja] print “stock: %s”% stock[ja]
It has just nearly pissed me off for just a space. Which wasn’t even an error.
Answer 551995209113cb6f5f006a2d
I’d like to add another example of “wrong” - was struggling with this untill I just copied from somebody else who said his code works:
WRONG: for key in prices: print(key) print(“price: %s” % prices[key]) print(“stock: %s” % stock[key])
removing the brackets made it work.. :)
Answer 55363a3c9113cbfd4a000122
My errors according to the code checker were missing spaces:
- between the print and the double quotes print”price %s… -> wrong print “price %s… -> correct
- after the %s print “price %s “ % prices[key] -> wrong print “price %s” % prices[key] -> correct
Answer 5553e2b1e39efee67b000385
Answer 5567b167e39efeceba000206
The code checker responsible for accepting the exercise is cap sensitive. I also took liberties with the text string and added an “s” to “price”. This is a no-no… :(
Specifically: 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 “Prices: %s” % prices[key] print “Stock: %s” % stock[key]
Answer 5569d1ab76b8fe1493000749
I received an error for capitalizing Price and Stock - make sure these are lower case everywhere in the code.
Answer 557dbfc576b8feadb000058b
after tons of tries what a foolish it’s just one space between (:) and (%s)
print “price: %s” % prices[key] print “stock: %s” % stock[key]
Answer 558f82539113cb0c5c000707
I was going crazy because I had “Price” and “Stock” capitalized. Truly one of the stupidest errors I have ever seen.
Answer 559972ce9376767b0d00050c
write price instead of prices or Price
price = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
for key in price:
print key
print "price: %s" % price[key]
print "stock: %s" % stock[key]
1 comments
That worked for me too! I have exactly the same code.
Answer 55b64cb076b8fef1900003e1
For me, my error was that I was using:
for key in prices: print "%s: " % key; print "price: %s" % prices[key]; print "stock: %s" % stock[key];
Though print "%s: " % key
produces the same exact result as print key
, the code is not accepted. Make sure to simply use print key
.
Answer 55b7190076b8fe3bd00008ae
Answer 55bc899fe39efe3069000381
this will work….
First one
prices = { “banana”: 4, “apple”: 2, “orange”: 1.5, “pear”: 3 }
stock = {“banana”: 6, “apple”: 0, “orange”: 32, “pear”: 15}
for i in prices : print i print ‘price: %s’ % prices[i] print ‘stock: %d’ % stock[i] print
another one…..
prices = { “banana”: 4, “apple”: 2, “orange”: 1.5, “pear”: 3 }
stock = {“banana”: 6, “apple”: 0, “orange”: 32, “pear”: 15}
for i in prices : print i print ‘price: %s’ % prices[i] print ‘stock: %s’ % stock[i] print
Answer 55bc8fc1937676d7c10007d4
Answer 55d602ace39efe58cf000099
Answer 55f383c7d3292f6da000054f
correct code for key in prices: print key print ‘price: %s’%prices[key] print ‘stock: %s’%stock[key]
we have to leave a space before %s so output can be in given format.
Answer 55fc58ffe39efe9b59000072
Answer 5609f45cd3292f577900033f
I reread the hint.
You should print the number all by itself—no need for any additional text!
Once I took all the text (stock: & price:) and just printed the numbers. It passed yeah!
Answer 561213f2d3292f2e980002a4
TRY RELOADING YOUR PAGE WHEN YOU THINK YOUR CODE IS CORRECT. AFTER ONE HOUR OF AGONIZING I CUT AND PASTED MY CODE BACK IN AND IT PASSED. (AFTER THREE PAGE RELOADS AND RESETTING FOUR TIMES!!!!!!) CODEACADEMY HAS BUGS!!!!!!!!!!!!!! (THEY WON’T ADMIT IT)
Answer 56127af3e39efedf1a000279
print “price:”, prices[key] print “stock:”, stock[key]
output is correct but lesson fails
Answer 5615a3959113cb888e00009f
No matter what I try, it refuses to pass my code. This is simply not possible.
Answer 5500ae31d3292fb6120011c4
Answer 55478335e39efe8a8d000017
_ _______
| | / \
_____|_|________/ \
/ \
/ ___ ___ |
/ (_|_) |_|_| |
| |_|_| |
| __ |
| | .| |
| | | |
|++++++++++++++++++++++++++++++|
Look at this baller house.
4 comments
yeet
this is legit the real code answer
what is this??
cool
Answer 55f2ad209113cb25ba0003fb
Codeacademy really shouldn’t take price instead of prices, it doesn’t matter what the dictionary string is named, when you print it it should be the same string, computers don’t understand English grammar. We are learning Python not grammar this frustrated me a lot
Answer 54de3249e39efe05ef002391
For me the issue was with the s.
for key in prices: print key print “prices: %s” %prices[key] #Notice the prices instead of price print “stock: %s” %stock[key] print
The print should not be the same as the key i guess.
Answer 54ea8a6b9376762f66004a1b
Stupid… Why “for a in prices” is not correct? Why only “for key in prices” is accept?
1 comments
both of those are correct, you are doing something else that isn’t
Answer 54deeee451b8879d07003be4
print “prices: %s” % prices[key] # False print “prices %s” % prices[key] # False print “price %s” % prices[key] # False
print “price: %s” % prices[key] # True
STUPID STUPID STUPID # True
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
13 comments
I think so!
Agreed some very tricky hints to follow!
The code academy lab doesn’t complain about the capitals. Its the editor.
this one nearly got me depressed !! “orange is not the new black ! its a not so helpful hint !! “ :)
thanks a lot this was very helpful.
Just another example of a cryptic error message. Get used to it.
OK now this is weird . I used %d instead of %s to get the ‘key_value’ associated with the key to be printed. The strange thing is that the output is exactly as expected but the same ‘Orange’ error throws up.. shouldnt one use the %d , as the numbers are integers rather than strings ?? please advice
thx
The initial list is given as “prices,” so my assumption now is that this is done to see if you’re on the ball. Fair enough
I feel angry now
I was losing my mind. GOD! thanks
ty
I agree. I don’t have two hours to stare at a screen looking for an error when no info is being provided as to why. Fix your error messages or add this clearly to hints