8.Keeping Track of the Produce


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 "prices: " + str(prices[item])
print "stock: " + str(stock[item])

It should be OK but it doesn't work mates.

(" Check what your code prints for orange. It doesn't look quite right!")


Hello, @devslayer44579!
Make sure the way it's shown to you in the instructions is the same way you're actually printing that out.
If even after fixing that, the code doesn't work try adding %s, which is a place holder and will there your program where to replace %s with a value or something, at each statement.

If it doesn't work, let us know!


Could you tell where I did wrong?

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]


@davistian125: Check if you're supposed to print prices or price and also the space between " : " and placeholder %s.


try this , i had the same problem and it worked for me ,

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

i guess you have to turn the value of the key into a string to concatenate
hope this works for you .


except dont forget to indent

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


how did you get the prices of the items @davistian125