Keeping Track of the Produce


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3?curriculum_id=4f89dab3d788890003000096


Oops, try again. Check what your code prints for orange. It doesn't look quite right!


It looks ok to me, I didn't understand the problem.


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: %s" % prices[item]
    print "stock: %s" % stock[item]


#2

My guess is it doesn't like prices being plural in your print statement.

Try print "price: %s" % prices[item]


#3

Yep it worked thanks a lot but I really didn't understand the logic this time.


#4

What part of the logic didn't you understand?


#5

Ah OK I got it now. It is only a string and in the exercise it needs to be printed as price. I just thought we are talking about the dictionary. Thanks a lot again.


#6

Oh haha, sorry about the confusion. Yes, it's just a string in the print statement that codecademy is particular about. The dictionary is fine.


#7

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

ERROR:Oops, try again. Check what your code prints for orange. It doesn't look quite right!

I tried the plural thing u told....didnt work out...:frowning:


#8

Did you try it like this:

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

I think there were actually two things throwing it off.
1. price needs to be without the 'S' on the end.
2. There needs be a space between price: and %s and stock: %s


#9

link : https://goo.gl/iEztBn
It's showing the error : Oops, try again. Check what your code prints for orange. It doesn't look quite right!

My code :
prices = {"banana": 4,"apple": 2,"orange": 1.5,"pear": 3}
stock = {"banana": 6,"apple": 0,"orange": 32,"pear": 15}

for fruit in prices :
print fruit
print "prices : %s" % (prices[fruit])
print "stock : %s" % (stock[fruit])

It's showing the error : Oops, try again. Check what your code prints for orange. It doesn't look quite right!


#10

I just don't get why in the illustration at the top, they write "Once: %s.." and "Twice: %s..."
Where they have written the dictionaries with capital first letter, which was what that confused my terminal. That is really confusing! Other than that, the rest is correct!


#11

From the thread I see everyone is having the same problem. The error is coming about because the code:
for fruit in prices:
print fruit
will print out the all values for the keys. Remember that all the keys were assigned to the variable fruit.
So the issue is how to print the keys for the dictionary.


#12

Scratch that....I've gone through my code and it works okay as long the variable set after for is the same one printed out. So the above code is okay.


#13

prices = {"banana": 4,"apple": 2,"orange": 1.5,"pear": 3}
stock = {"banana": 6,"apple": 0,"orange": 32,"pear": 15}

for fruit in prices :
print fruit
print "price: %s" % prices[fruit]
print "stock: %s" % stock[fruit]

I got the same error, I just took the space after print "price: %s" % prices[fruit]
print "stock: %s" % (stock[fruit]) and also the "s" for prices


#14

@salma_gherraby, check out my code too: with same error about the print out for orange

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

I haven't figured how to work it out yet


#15

check your indentation.....the last two prints are not properly indented


#16

Hey you check your indentation. for print fruit. That is the problem


#17

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

for food in prices:
print food
print "price: %s" % prices(food)
print "stock: %s" % prices(food)

I can't quite figure out where I am going wrong here...


#18

When accessing items in a list or dictionary you need to use brackets and not parentheses. Change prices(food) to prices[food]


#19

this is my answer

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: %s" % prices[item]
print "stock: %s" % stock[item]

your indentation is not good, for the print


#21

I finally figured it out @vhans and @salma_gherraby . The correct code is:

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