10.8 Keeping track of the Produce.What's wrong with my code prints for orange?


#1

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]

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


10.8 Keeping track of the Produce
#2

Small, tiny error: "prices" in your loop needs to be written as "price" to be seen as correct by Codecademy, as in the format it asks for in the directions.

so correct altogether it'll 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]


#3

My code looks exactly like that and it is still wrong.

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]


#4

Take off the capitals of the beginning of the sentences and that should work :smile:


#5

My code has any problem? Why it can't work? And it always print the info from "orange" but not "banana", why? Please help me :disappointed_relieved:
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])


#6

Try without the parentheses in your print commands.


#7

hello :smile:
My code prints:
orange
price:1.5
stock:32
pear
price:3
stock:15
banana
price:4
stock:6
apple
price:2
stock:0
None

but it still gives: Oops, try again. Check what your code prints for orange. It doesn't look quite right! Can you please help?


#8

sorry, the problem was rectifiied when I went to the next lesson using the section menu, completed it and then came back to my code and run it!


#9

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]

Error i am getting "Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)"

Any clue please?


#10

:smile: :smile: you right betaace...just take off the capitals and it should be fine..thanks..


#11

I get the error: Oops, try again. Check what your code prints for orange. It doesn't look quite right!
but everything seems right.
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]

the output seems right too:
orange
price:1.5
stock:32
pear
price:3
stock:15
banana
price:4
stock:6
apple
price:2
stock:0
None


#12

Try putting a space after the colons of "price" and "stock" in your print commands.
The new code should look like this:

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

It should work. :smile:


#13

You should put spaces after your print commands, and also before the percentages after the colons in the new code.
It should look like this:

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

It should work. :smile:


#14

Hi,
why my code don't work ?


#15

In line 17th use print "price: %s" it's NOT prices


#16

Ok, and what is wrong with mine?


#17

remove the space between %s and the quote (") .


#18

I was having the same issue about "oranges", and was able to fix it after changing 'prices' to 'price'.


#19

hey boss , remove space in "orange": 32 == "orange":32 and enjoy


#20

Faced same problem, try below code its working fine

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

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