Keeping track of products

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 “prices : %s” % prices[food]
print “stock : %s” % stock[food]

i do not know what to do with this exercise

What you do is printing all the products, you need to print only the apple

i have this but dont work, beside the right answer:
prices = {
“banana”: 4,
“apple”: 2,
“orange”: 1.5,
“pear”: 3
}

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

for key in prices:
print “apple”
print “Price %s” % prices[“apple”]
print “Stock %s” % stock[“apple”]
break

My bad, it’s for print everything. You need to use key insted of food

You need to have proper spacing between
price: and %s
stock: and %s

example below
for key in prices:
print key
print “price: %s” % prices[key]
print “stock: %s” % stock[key]

HI,

I am using the same but its throwing an error. "Oops, try again.
Check what your code prints for orange. It doesn’t look quite right!
"

Hi

My answer appears correct - and yet the message indicates "Oops, try again. Check what your code prints for orange. It doesn’t look quite right!’- the orange price and count are correct. can you see what the problem is?
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]

2 Likes

took another look (more like the 15th time). the tutorial ask that we print “price” and “stock” NOT “Price”, "Prices nor “prices” or “Stocks” nor "stocks…

so it should be -
print key
print “price: %s” % prices[key]
print “stock: %s” % stock[key]

hope this helps

11 Likes

Guys, little help here, I don’t understand where is the mistake
It says:- “Oops, try again. You should have exactly three print
statements! (Make sure there are no occurrences of
‘print’ in any comment or string!)”

Here z my code -:

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(“price: %s” % prices[key])
print(“stock: %s” % stock[key])

This is what your code should look like

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 “price: %s” % prices[key]
print “stock: %s” % stock[key]

oh yes, i got it actually i have to put some space after each print statement

Guys need help please!

Hi @oakzd ,

You have the for loop formatted as follows …

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

To make Codecademy happy, you will need to place a space between print and the first " mark, in the second and third print statements. To format the output according to the instructions, you will also need to remove the space that occurs between the %s format specifier and the following " mark in those two statements.

After making those corrections, you should have this …

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

@geomaticmashups
thanks so much!!

thats good but you need to indent all the prints at the bottom

be sure to put a tab in the print parts

Actually u jus need 2 print apple only. Like this:

prices = {
“apple”: 2
}
stock = {
“apple”: 0
}
for key in prices:
print key
print “price: %s” % prices[key]
print “stock: %s” % stock[key]
break

And u can put the “break” or don’t put it.

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 “price: %s” % prices[key]
print “stock: %s” % stock[

So any ideas:

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 “Price: %s” % prices[key]
print “Stock: %s” % stock[key]

please see above answers you have to indent the block of print commands after the for statement, like this: ( _ states for space)

for key in prices:
____print key
____print “Price: %s” % prices[key]
____print “Stock: %s” % stock[key]