8. Keeping Track of the Produce


#1


Hi all,

I seem to have the common error of:
"Oops, try again. Check what your code prints for orange. It doesn't look quite right!"

Can anyone help?! Code below

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


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

Hi you should indent these line too

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

then remove the space before the :


#3

Mine does not work either, and it's indented and does not have the space you advised removing...

Any other suggestions? I am getting the same error as jordanmich.


#4

@jordanmich @btj8d0 the only differences I have in my code are the ones @wizmarco described, but, and this may not even matter, I do have ()'s surrounding my:

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

like this:

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

the only reason I am saying this is because sometimes it wont pass you even if you have something small like that, even if it would work outside of codecademy.


#5

Okay, never mind, I got it! It had to do with where I used "price" and where I used "prices"

("price" being what they asked you to print, "prices" being the name of the dictionary)


#6

Could I bother you for a screenshot of what happens when you press save & submit please


#7

Hello,

I got this error. Here is my screenshot

Edit: I wrapped str() around they number, and it's letting me pass now.


#8

HI try To Read all My first post

Hint

print "price: %s" % prices[key]
print "stock: %s" % stock[key]
then remove the space before the :


#9

that's weird I'm honestly not sure what the problem is. try and removing the space before the colons again here:

and let me know if that works


#10

I had the exact same code and the exact same problem. I fixed it by changing 'prices' to 'price' on line 1 and the first 'prices' on line 16. It looks like this:

price = {
"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])

Hope this helps!


#11

Hi Wizmarco,

Still no change to the error after changing the indent and adding ().


#12

I honestly can't see where I'm making the mistake here, code below.


#13

The last two lines need to be indented so they are in the for block.


#14

Thanks Mtf, that seems to have fixed it.