8/13 "something wrong with the orange"


#1

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]

I got this error "Oops, try again. Check what your code prints for orange. It doesn't look quite right!"

I saw some other posts here discussing the same problem. I tried some of the solutions, but the error message still pops up.

Any help? Thanks


#2

Problem solved. I changed this line

print 'prices: %s' % prices[key]

to

print 'price: %s' % prices[key]


#3

Just mentioning that in my case it was a question of extra spacing.


#4

I've tried everything from the posts about orange, but obviously I am missing something. Here is my code. I would be grateful for any advice on this

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\n"  % stock[key]

#5

Hello!!! my code is:

prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1,
"pear": 3}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 7,
"pear": 8}

for key in prices:
print key
print "cost: %s" % prices[key]
print "quant: %s\n" % stock[key]

But this error ocurred:
Oops, try again. Check what your code prints for orange. It doesn't look quite right!

What´s wrong???


#6

I got the same thing, and I couldn't solve it even thought the code was perfect:
just copy this and it should work:

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]


#7

I've been stuck on this exercise for three days just because I put captial's on price and stock. Very annoying!


#8

Even I am stuck with the exercise .. what is the problem with orange.


#9

print "price: %s"%prices[n]
print "stock: %s"%stock[n]

I got this thing right..FYR


#10

Thank you. I wonder why the code doesn't seem to work normally for everybody?


#11

What the... this saved a lot of my time... Thanks!!!


#12

In case this helps anyone:

The validator would not accept capitalized versions. For example, my code was:

print item
print "Price: %s" % prices[item]
print "Stock: %s" % stock[item]

It would only accept:

print item
print "price: %s" % prices[item]
print "stock: %s" % stock[item]


#13

The spaces should be correct as if in the example shown....I too confused about this for a long time...
My code worked at last...
print key
print "price: %s"%prices[key]
print "stock: %s"%stock[key]


#14

can some one tell me why this is?

Is this just what Codeacademy looks for its not actually an error in python itself?

"prices" being "price" that is.


#15

Thanks! this helped. Im not sure why mine didnt work. It was the same thing... :frowning:


#16

Completed, but can someone explain how "key" outputs the string when "print key", but then a number when applied to the dictionary?


#17

Not even here, There are code check issues at many stages of the program.
Just move on to the next slide. Don't hang on there. It's not your fault.


#18

This worked. It's ridiculous that that was the cause of not accepting the code :s


#19

I like how everyone is trying to over-complicate the exercise. The majority of the time that people receive errors is due to the indexing and relational components of the exercise. The more concise your program is the more likely you are to receive errors. If someones code worked and is identical there could be a microscopic mistake such as a additional space. Considering this is the method in which all the Python tutorials you should definitely try to retype the entire portion to try and get the exercise correct considering all the exercises are linked together skipping one will allow you to not be able to move on to the next or make it near impossible for you to move on to the next exercise with a completion. The Structure in my opinion is very useful and applicable skill when learning new languages.

Just some advice from a person who struggled but finally came through in the end.


#20

Thank you! I don't think I'd be able to find out that this was the problem myself. It's ridiculous!