Whats wrong i cant print orange?


#1



Replace this line with your code. 
prices={
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
    }
    
stock={
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
    }
for  x in prices:
    print x
    print "prices : %s" %prices[x]
    print "stock  : %s" %stock[x]


#2

What's stopping you?

Your code has the following output:

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

So you very much seem to be able to print orange. Perhaps you're wondering about something other than what you're asking about? Make sure to ask for what you're after. Be specific!


#3

@ionatan there a error which says orange is not printed


#4

Dunno, maybe it's saying something other than what you say it says. Maybe you changed the meaning of the error message and that is causing you to look for a different problem than it's actually talking about?

For example, if it says you printed orange differently from what it expects, then that's not the same as not having printed it at all.

If it says you print it differently, then what can you do about that?


#5

here the error msg : Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#6

See. Entirely different. What can you do about it? What's stopping you from fixing that? It describes what is different about your program's behaviour.

You didn't consider what the error message said!


#7

it prints the exact details idk what the problem maybe i willl see one more time


#8

If it says it wasn't printed "quite right", then compare to what the instructions say is right. Right?


#9

I have tried it out multiple times :sweat:


#10

Have you compared what instructions describe to what you print?
There instructions include an example. Can you tell the example apart from what you print?

The instructions say to use the same format as that example. If you can tell them apart, then you didn't use the same format, or there would be no difference.


#11

You need to have the : directly after price and stock in the print lines.no spaces after each word.

should look like this print "price: %s" print "stock: %s"


#12

got it ! thanks this is crazy just a space made the whole difference :smile: @jonesandrewk @ionatan


#13

hey.. the same problem for me.
I've entered the code like this-
print "prices: %s" %prices[x]
print "stock: %s" %stock[x]

but it's not working.
anymore spaces to avoid?


#14

And that's why you should compare instead of jumping to the conclusion that the spaces are wrong. Compare your output to the described format.

If it's the same problem then the answer is the same. If the same answer doesn't apply, then it's not the same problem! You're making a whole lot of assumptions here, and it's hurting your reasoning!


#15

I have the same problem too.


#16

it worked bro.! the problem is not with our codes. It's this that codecademy only takes one type of output and returns error for all other outputs may it be correct or not. Just check my code, i'm dropping it below. :wink:
prices = {'banana':4,'apple':2,'pear':3,'orange':1.5}

stock = {"banana":6,'apple':0,'pear':15,'orange':32}
for x in prices:
print x
print "price: %s" %prices[x]
print "stock: %s" %stock[x]

here, in the 2nd print command, it would be written prices. go change that to price. I have changed it in mine, so just copy paste and try this code. it will surely work.


#17

Yeah, I had a similar problem. I have an unrelated question, though. Why does oranges print first, instead of banana?


#18

Hi @scriptplayer61355 ,

A brief answer to that unrelated question is on this page: A Day at the Supermarket: This is KEY!.

A Python dictionary is an example of a hash table. For lots of details, perhaps more than you asked for, see Wikipedia: Hash table. Hash tables are really cool and very useful.


#19

The words "price" and "stock" must be written in small letters

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


#20

The words "price" and "stock" must be written in small letters

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