A day at the Supermarket


#1


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!


prices = {"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3}

stock = {"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15}
for i in prices:
    print i
    print 'prices: %s' % prices[i]
    print 'stock: %s' % stock[i]


#2

Please post your code.


#3

prices = {"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3}

stock = {"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15}
for i in prices:
print i
print 'prices: %s' % prices[i]
print 'stock: %s' % stock[i]


#4

Hi, your code is correct, i guest it just CodeCademy want you to output the result exactly the same as in the instruction.

change this line:

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

to:

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

I tested your code, and it work!


#5

Thanks for your reply. yes it worked.


#6

Hey, my code isn't working and I can't figure out why:

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

#7

Hi,

Please do the following modification:
please add 1) print key
2) please add s after modulo, like below code:
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
your code should look like below code:
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]


#8

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