8,Keeping Track of the Produce


#1


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

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


i've put the the correct value for orange as in the instruction
so what did i miss ?.


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


#2

Works for me.

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

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}


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

#3

try doing like this

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

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}

instead of this

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

#4

still the same error appear


#5

I think i found the error. It expects

print "**price**: %s" % prices[item] # not prices

I tested it and it should work now.

Alternatively, you could do something like this, which i find less confusing :

for item in prices:
    print item
    print "price: "+ str(prices[item])
    print "stock: "+ str(stock[item])

#6

thank you so much
this code really works.

both of the codes was right,

for item in prices:
    print item
    print "price: "+ str(prices[item])
    print "stock: "+ str(stock[item])

and this code also works well,
where I've misspelled the price :

or item in prices:
    print "%s" % item
    **print "price: %s" % prices[item]**
    print "stock: %s" % stock[item]

#7

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