This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Jonatan
over 9 years

[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

64 votes

Permalink

Thanks Anyway, I really think the error remind of “check orange” is stupid…

points
Submitted by zliu43
over 9 years

13 comments

KaiWang almost 9 years

I think so!

Danny Large almost 9 years

Agreed some very tricky hints to follow!

GangstaCoder over 8 years

The code academy lab doesn’t complain about the capitals. Its the editor.

vivekchellappan over 8 years

this one nearly got me depressed !! “orange is not the new black ! its a not so helpful hint !! “ :)

Bigbuck2605 over 8 years

thanks a lot this was very helpful.

Brian Norton over 8 years

Just another example of a cryptic error message. Get used to it.

vivek c over 8 years

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

eshab over 8 years

thx

joejoe52 over 8 years

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

Naoki Yang over 8 years

I feel angry now

ThelmaV over 8 years

I was losing my mind. GOD! thanks

Jeremy Thompson over 8 years

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

Answer 556eea339113cba68d000652

14 votes

Permalink

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”

points
Submitted by Michal Jeřábek
almost 9 years

12 comments

Adam Gasparovic almost 9 years

Thanks

寿司寿司17 almost 9 years

Thanks a lot!

sainarayanan over 8 years

awesome thank u

GangstaCoder over 8 years

thx

cathy hsu over 8 years

thx i still cant figure out why my code is wrong, it looks exactly the same

Eddie Gu over 8 years

thx

Michael Nguyen over 8 years

Thank you

David Rosenberg over 8 years

same thing happened here. Be sure to write “ print: “price: %s” not prices

Jazzz over 8 years

thank you

Andy over 8 years

Solution worked for me - thanks for sharing

FonnY12 over 8 years

thx

Ulvi Yelen over 8 years

worked! thx. it’s about colons space

Answer 54d437ea86f5521c5d000ee9

11 votes

Permalink

Don’t write Price instead of price and Stock instead of stock.

points
Submitted by santosa.sp
about 9 years

3 comments

Roxas almost 9 years

This.

pkfd55 over 8 years

thanks, it helps a lot

MarkWinston over 8 years

THIS! Thank you!

Answer 54a0674d9113cbc7e301334c

9 votes

Permalink

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!

points
Submitted by Sameeksha Aithal
over 9 years

9 comments

Dred about 9 years

I was pulling my hair out till i realized that I had and additional space as well….

Travis House about 9 years

..same here :)

wingchiang about 9 years

mine still doesn’t work:(

Dhiral Panjwani over 8 years

Not working :(

Vaibhav Ahuja over 8 years

exactly..thank you. same space/ was there dude

dj.ca over 8 years

I forgot the : deep sigh

Arbalest Zhang over 8 years

Thanks a lot.

RajyaLakshmi.M over 8 years

Yeah…Space really counts…Thanks a lot!

Praylin over 8 years

Thank you… I too had the same problem…

Answer 549a87709113cb428d00afaa

1 vote

Permalink

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.

points
Submitted by Kush Parikh
over 9 years

4 comments

Shubham Chhabra over 9 years

yeah it would give 1 instead of 1.5 for stock value of orange.

Jonatan over 9 years

%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

Elenka080 about 9 years

Thank you!!!!!!

Craig Schaefer about 9 years

%r also worked for me.

Answer 549fef0ed3292f9d52012143

1 vote

Permalink

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

points
Submitted by WimLawrence
over 9 years

1 comments

Clement about 9 years

Oh sorry I did not see this:_(

Answer 54a965d4d3292f49b0007388

1 vote

Permalink

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.

points
Submitted by DataMinerGo
about 9 years

2 comments

Bergur about 9 years

Worked for me

Swapnil almost 9 years

worked for me i used “Price” instead of “price”

Answer 54fcd15ae39efef98e002997

1 vote

Permalink

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.

points
Submitted by Carter Meeks
about 9 years

1 comments

John Koterba almost 9 years

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

1 vote

Permalink

Thank you so much! Wish I could upvote your answer!! My error was capitalizing “Prices” in the output

points
Submitted by Wesley Swafford
about 9 years

Answer 552b802795e378b6b3000263

1 vote

Permalink

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.

points
Submitted by Campbell Boyd
almost 9 years

Answer 5560b8dd9113cb0297000100

1 vote

Permalink

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]

print

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.-

points
Submitted by Santiago_77
almost 9 years

Answer 559d1039d3292ffba300067f

1 vote

Permalink

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]

points
Submitted by put91
over 8 years

2 comments

hxxxxxx over 8 years

It is wrong…

2020orczesc over 8 years

yeah its wrong please remove comment

Answer 55a10d299376761c8d0003bf

1 vote

Permalink

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

points
Submitted by Rajni Rajai
over 8 years

Answer 55f454b6e39efe454c0005e9

1 vote

Permalink

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.

points
Submitted by Carlo DiCelico
over 8 years

Answer 548f71d295e378218500002f

0 votes

Permalink

Thanks. That was maddening

points
Submitted by Edward Arcuri
over 9 years

2 comments

Andrea Faré over 9 years

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…

Eric Goode almost 9 years

It’s especially maddening when the instructions use prices…

Answer 5490699795e378eb9f001e29

0 votes

Permalink

Surely the example text is wrong then?

print “Once: %s” % once[key] print “Twice: %s” % twice[key]

points
Submitted by blueboy57
over 9 years

1 comments

jonstong about 9 years

it just doesn’t have the first line “print key”

Answer 549e462376b8fef01500f9f5

0 votes

Permalink

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!”

points
Submitted by Vic Hargrave
over 9 years

6 comments

Sameeksha Aithal over 9 years

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

esingingmonster about 9 years

Also, I think that you may have the wrong stock numbers.

pratik sangpal about 9 years

just put the %s format specifier and take care of spaces you add.

Ben almost 9 years

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.

Ben almost 9 years

Another bug. This site cleared my formatting. I’m on Mac 10.9.5 on latest chrome

tvirg almost 9 years

you put print “Price: %f” % prices[key] instead of print “price: %s” % prices[key] the difference is the %f and %s

Answer 549e46d486f552877c00ef60

0 votes

Permalink

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.

points
Submitted by Vic Hargrave
over 9 years

8 comments

Nickolai Levis about 9 years

you need to lower case Price and Stock

xuhuapeng about 9 years

中文 Chinese

Clement about 9 years

Ok so…..what is the relevance of Chinese? Lol

Clement about 9 years

maybe its cuz your putting price and stock in upper case instead of lower case vic. Hope that helps

Marc almost 9 years

Yes this was my issue, didnt think the string would matter upper or lowercase

Rafael Herazo almost 9 years

maybe it’s the f after the %sign after print “Price”

Swapnil almost 9 years

use lower case letters like “price”,”stock” or the interpreter will throw an error

Tony_Nguyen_Anthony over 8 years

you should leave it only like print “Price: %s “ % prices[key] hope this helps print “Stock: %s” % stock[key]

Answer 54ca12ea95e37824440014df

0 votes

Permalink

OOOOOh~This make me crazy!!

points
Submitted by shrodingerdecat
about 9 years

1 comments

hxxxxxx over 8 years

yep

Answer 54ce91c276b8fe8698004562

0 votes

Permalink

Capitalization for the fail! I was proud of myself for finding this mistake on my own without consulting the forums! Thanks for backing up my supposition!

points
Submitted by Xanderoid
about 9 years

Answer 54d3019086f5523d78001c8c

0 votes

Permalink

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]

points
Submitted by feimengchang
about 9 years

Answer 54d8b53286f5523b88009349

0 votes

Permalink

I was stuck for a while because of:

… print “price: “, prices[key] print “stock: “, stock[key] …

This produces output that looks exactly the same, but the grader returns an error.

points
Submitted by blammox
about 9 years

Answer 54e5dbe0e39efe4cc70016b9

0 votes

Permalink

This is plain crazy.It should not matter if we write Price instead of price its senseless. Moreover I am still getting the error message after doing all that was mentioned as a solution in this post but nothing good came out of it.

points
Submitted by py2abhi
about 9 years

Answer 54f712409376763ced001de7

0 votes

Permalink

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.

points
Submitted by pratik sangpal
about 9 years

Answer 551995209113cb6f5f006a2d

0 votes

Permalink

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.. :)

points
Submitted by Pim
almost 9 years

Answer 55363a3c9113cbfd4a000122

0 votes

Permalink

My errors according to the code checker were missing spaces:

  1. between the print and the double quotes print”price %s… -> wrong print “price %s… -> correct
  2. after the %s print “price %s “ % prices[key] -> wrong print “price %s” % prices[key] -> correct
points
Submitted by Wael El Essawy
almost 9 years

Answer 5553e2b1e39efee67b000385

0 votes

Permalink

telling how the specified output would be formatted would be nice.

points
Submitted by tdajos
almost 9 years

Answer 5567b167e39efeceba000206

0 votes

Permalink

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]

points
Submitted by Orson
almost 9 years

Answer 5569d1ab76b8fe1493000749

0 votes

Permalink

I received an error for capitalizing Price and Stock - make sure these are lower case everywhere in the code.

points
Submitted by bitBlaster80668
almost 9 years

Answer 557dbfc576b8feadb000058b

0 votes

Permalink

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]

points
Submitted by pythogrammer
almost 9 years

Answer 558f82539113cb0c5c000707

0 votes

Permalink

I was going crazy because I had “Price” and “Stock” capitalized. Truly one of the stupidest errors I have ever seen.

points
Submitted by netCoder39800
almost 9 years

Answer 559972ce9376767b0d00050c

0 votes

Permalink

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]
points
Submitted by Aimee
over 8 years

1 comments

lueersen over 8 years

That worked for me too! I have exactly the same code.

Answer 55b64cb076b8fef1900003e1

0 votes

Permalink

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.

points
Submitted by Mark Carbonaro
over 8 years

Answer 55b7190076b8fe3bd00008ae

0 votes

Permalink

Very helpful post! I was so confused with the error message “check orange” . Thanks a lot!

points
Submitted by He
over 8 years

Answer 55bc899fe39efe3069000381

0 votes

Permalink

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

points
Submitted by nihit425
over 8 years

Answer 55bc8fc1937676d7c10007d4

0 votes

Permalink

#this is correct prices = { “banana”: 4, “apple”: 2, “orange”: 1.5, “pear”: 3 }

stock = { “banana”: 6, “apple”: 0, “orange”: 3, “pear”: 15 }

for key in prices: print key print “price: %s” % prices[key] print “stock: %s” % stock[key]

points
Submitted by Dinesh
over 8 years

Answer 55d602ace39efe58cf000099

0 votes

Permalink

    }

for key in prices:

print key print “price %s” % prices[key] print “stock %s” % stock[key]

Wrong

    }

for key in prices:

print key print “price: %s” % prices[key] print “stock: %s” % stock[key]

Correct? Spacing???? Sigh~

points
Submitted by lisuda
over 8 years

Answer 55f383c7d3292f6da000054f

0 votes

Permalink

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.

points
Submitted by Shivam Sharma
over 8 years

Answer 55fc58ffe39efe9b59000072

0 votes

Permalink

price, not prices Thanks, I would’ve spent way to log staring at code that was correct with words that weren’t. ^_^

points
Submitted by Derek
over 8 years

Answer 5609f45cd3292f577900033f

0 votes

Permalink

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!

points
over 8 years

Answer 561213f2d3292f2e980002a4

0 votes

Permalink

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)

points
over 8 years

Answer 56127af3e39efedf1a000279

0 votes

Permalink

print “price:”, prices[key] print “stock:”, stock[key]

output is correct but lesson fails

points
Submitted by Petr Matlas
over 8 years

Answer 5615a3959113cb888e00009f

0 votes

Permalink

No matter what I try, it refuses to pass my code. This is simply not possible.

points
over 8 years

Answer 5500ae31d3292fb6120011c4

-1 votes

Permalink

Really?! I can’t name it whatever I want? I must say price and not prices because it’s checking my grammar? This was infuriating.

points
Submitted by awhite28
about 9 years

Answer 55478335e39efe8a8d000017

-1 votes

Permalink

         _           _______    
        | |         /       \
   _____|_|________/         \
  /                           \
 /    ___           ___        |
/    (_|_)         |_|_|       |
|                  |_|_|       |
|           __                 |
|          | .|                |
|          |  |                |
|++++++++++++++++++++++++++++++|

Look at this baller house.

points
Submitted by Nicolas DeMasi
almost 9 years

4 comments

Ryan_Thiret_34 almost 9 years

yeet

Ryan_Thiret_34 almost 9 years

this is legit the real code answer

avnt almost 9 years

what is this??

2020orczesc over 8 years

cool

Answer 55f2ad209113cb25ba0003fb

-1 votes

Permalink

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

points
Submitted by capntam
over 8 years

Answer 54de3249e39efe05ef002391

-2 votes

Permalink

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.

points
Submitted by Tauseef Hussain
about 9 years

Answer 54ea8a6b9376762f66004a1b

-3 votes

Permalink

Stupid… Why “for a in prices” is not correct? Why only “for key in prices” is accept?

points
Submitted by xAYKx
about 9 years

1 comments

Jonatan about 9 years

both of those are correct, you are doing something else that isn’t

Answer 54deeee451b8879d07003be4

-6 votes

Permalink

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

points
about 9 years