Orange error


#1

the orange error

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3?curriculum_id=4f89dab3d788890003000096

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

but ,according to me code is alright!!

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])

#2

I had the same problem and couldn't find anything wrong in above coding.


#3

i have the same, tryed to remove "orange" but it says the same error but with pear istead


#4

This exercise is very strict about formatting.

Your one of the o/p should look like this..

orange
price: 1.5
stock: 32

Can you find any difference(s) ?


#5

My output looks exactly like that. I also tried with and without an empty line between the keys, and still got this error.

this is a copy from my output:

orange
price: 1.5
stock: 32

maybe it's a bug


#6

Can you put formatted code?, use </> or 3 ticks.


#7

orange
price: 1.5
stock: 32

Is that okay?


#8

Code I meant ? :slight_smile:
(That's output)


#9

whoops sorry :smile:

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:", prices[key]
    print "stock:", stock[key]

#10

Try using string formatters as mentioned in example of this exercise.

once  = {'a': 1, 'b': 2}
twice = {'a': 2, 'b': 4}
for key in once:
    print "Once: %s" % once[key]
    print "Twice: %s" % twice[key]

#11

I used that before but with %d. I'm used to %s as for strings from C.
Anyway, it worked. thank you very much :blush:


#12

hey,can you pleas ehelp me out.
I am trying everything but it throws me the same error of orange.


#13

Hello @jaladi71,

Can you put your code here?
use </> or 3 ticks to format the code.


#14

Yes,
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]

can you look at this and tell me what should I do to correct it.


#15

Check this line..

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

and check my first post!


#16

Hey,I am not really getting it.

Can you tell me.
I have formatted in the way according to the example but it throws me the same error


#17

check string part, prices or price?:thinking:


#18

hey yeah its price,
I got it
Thankyouu


#19

I found that if you remove the space from before the colon in the stocks print then the original code works.

posted code:

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

fixed code. Output needs to be EXACTLY the same as per the example, spaces and all.

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

#20

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.