I'm getting a problem in printing the list values


#1



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

for item in prices:
    print item
    print "price: ",  prices[item]
    print "stock: ",  stock[item]


#2

Actually my data is getting printed, but its coming like " Oops, try again. Check what your code prints for orange. It doesn't look quite right! "
How to make it right and go ahead in codecademy


#3

you did't print out the value number but only "price: " and "stock: "
try these

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

or

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


#4

thank you soo much, i got cleared with my question @amberson


#5

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