Wrong code for orange?


#1



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


I put the correct code for orange, yet it says "Check what your code prints for orange. It doesn't look quite right!"


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 am not this far in python but just in looking at the code does orange need to be in ' ' rather than " " like all the other fruits?


#3

Sorry, I put ' and ' first but changed it due to the fact that it said wrong code for orange so i changed it to " and "

EDIT: i edited the post


#4

Your code is working, but is not passing the exercise, because the exercise is expecting variables with exact names. Capital or lower case do matter.

Price and price are different.


#5

I have the same issue and I have checked all variable names and they match exactly. I have refreshed my browser and this does not apper to solve the problem. I have a screenshot here of what is going on and how the problem

There does not seem to be anything that is able to solve the problem at the moment, has anyone got any help so that I can compleat this.


#6

Your code is correct. However, codecademy seems to checks for the exact variable names so instead of "print prices" it should be "print price". It was the same issue with mine except I had a capital letter but yours needs to be price instead of prices


#7

I'm having the same issue.

price = { "banana" : 4 ,
"apple" : 2 ,
"orange" : 1.5 ,
"pear" : 3 }
stock = { "banana" : 6 ,
"apple" : 0 ,
"orange" : 32 ,
"pear" : 15 }

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


#8

When you were defining the dictionary for prices, you forgot the s and only put price ={} so when you tried % prices, python didn't know what prices was.


#9

Thanks it works now. Glad I got that sorted now, spent ages on that one.


#10

Thanks! I've been trying this forever.


#11

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