Section 8


#1

I have no idea where I did wrong.
price={'banana':4,'apple':2,'orange':1.5,'pear':3}
stock={'banana':6,'apple':0,'orange':32,'pear':15}
for fruit in price:
print fruit
print "Price:%s" % price[fruit]
print "Stock:%s" % stock [fruit]
Error message: Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#2

Please you should learn to format your codes. This language is indentation sensitive.

Err,,, I'm trying to figure what exercise exactly but to loop in the the prices dictionary, you should do this:

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]