8.Keeping Track of the Produce


Every time I click save and submit, it tells me "Oops, try again! Check what your code prints for orange. It doesn't look quite right"
Here is my code:


Desired format:

price: 2
stock: 0

Output of your code:

prices: 1.5
stock: 32

Do you see a difference? :slightly_smiling:


I had same question, then I followed your reply, and it's solved. Thanks a lot~~


You're very welcome! :slightly_smiling:


factoradic, thanks, that really helped!


I see that your indenting is a little off. But I had a problem with the for loop. I'll show you my code and then tell you what I had wrong:

price = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
for product in stock:
print product
print "price: %s" % price[product]
print "stock: %s" % stock[product]

I don't know why it's such a pain to show the indenting in these posts. Anyway I see that you have an extra tab indent in your for loop for the print statements. That should have only one tab for each print statement because they are children of the parent for loop. The problem that I had is that it wants the output to not be prices with an s. Also my print statement didn't match exactly to what I was passing in for the stock and price. I had:
print "Price %s" % price[product]
print "Stock %s" % stock[product]

Since Price and price doesn't match and Stock and stock doesn't match it was throwing an error. I guess the capital P and S matters. I'm so used to Java and I still don't see why that matters anyway. Hope this helps in some way.