Keeping track of the produce. For Loop problem. Python


#1

Hi all, I am currently getting this error message: Oops, try again. Check what your code prints for orange. It doesn't look quite right!

I can't see what I am doing wrong. Could someone point out what I am missing? Thanks :slightly_smiling:.

Here is my code:
`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])`

Output from code being run:
orange
('price:', 1.5)
('stock:', 32)
pear
('price:', 3)
('stock:', 15)
banana
('price:', 4)
('stock:', 6)
apple
('price:', 2)
('stock:', 0)
None


#2

You don't need parentheses around print, as Codecademy uses Python 2.7.


#3

Thank you for pointing that out :slightly_smiling: . Do you have an idea on why I am getting this error message about orange?


#4

for item in prices:
print(item)
print('price:', prices[item])
print('stock:', stock[item])

You should print it like this:

print "price: " + prices[item]
print "stock: " + stock[item]

#5

Worked it out with your help :smile:. It was:
for item in prices:
print(item)
print "price: " + str(prices[item])
print "stock: " + str(stock[item])