8.Keeping Track of the Produce


#1

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:


#2

Desired format:

apple
price: 2
stock: 0

Output of your code:

orange
prices: 1.5
stock: 32

Do you see a difference? :slightly_smiling:


#3

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


#4

You're very welcome! :slightly_smiling:


#5

factoradic, thanks, that really helped!


#6

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.