Stuck at A Day at the Supermarket Part 8 in python


#1



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

I'm not having any errors, syntactical or any other. It just said:
Oops, try again. Check what your code prints for orange. It doesn't look quite right!

It says it doesn't print the right thing I guess.


prices = {
    'banana':4,
    'apple':2,
    'orange':1.5,
    'pear':3,
    }
stock = {
    'banana':6,
    'apple':0,
    'orange':32,
    'pear':15,
    }
for x in stock:
    print x
    print 'price:', prices[x]
    print 'stock:', stock[x]


#2

I tested your code and got the same error message. It would appear we need to use string formatting:

    print 'price: %s' % prices[x]
    print 'stock: %s' % stock[x]

#3

ok.. thanks..
But I hope there is nothing wrong in printing it the way I did it right?


#4

It's not wrong if Python doesn't burp. Once you move on to Python 3 (which I have yet to do) you will find that print() looks like a function, parens are required, and the old %s formatting is replaced with a .format() function.


#5

thanks a lot........