Keeping Track of Produce


#1

It keeps giving me an error stating that the console should only be printing 3 statements, one for each key, however there are 4 keys... I'm assume that I'm just missing something in my coding but I can't find it for the life of me. Help Please

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

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

for key in prices:
    print "%s\nPrice: %s\nStock: %s\n\n" %(key, prices[key], stock[key])

Here's the error: "Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)"


#2

Hi you should use the for loop for printing the price and the stock of each proprety yoh could do it like that

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

#3

That worked perfectly. Thank You!


#4

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 "prices: %s" % prices[key]
print "stock: %s" % stock[key]

The code gives me the error. "Oops, try again. Check what your code prints for orange. It doesn't look quite right!"
what should i do!!!


#5

Hi this part

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

you should remove the s from prices, so it should be

print "price: %s"....
....

#6

Thanks. It worked.:sunglasses::grin: