Keeping track of products


#1

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


#2

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


#3

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


#4

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


#5

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]


#6

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!
"


#7

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]


#8

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


#9

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])


#10

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]


#11

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


#12

Guys need help please!


#13

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])

#14

@geomaticmashups
thanks so much!!


#15

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


#16

be sure to put a tab in the print parts


#17

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.


#18

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[


#19

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]


#20

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]