8. keeping track of product : floating number problem


#1

Hi,
I check my code several times and match with the other threads
and it looks alright.
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: %d" %prices[fruit]
print "stock: %d" %stock[fruit]

The output for orange gives out "1": instead of "1.5" for its price.
what could the mistake be?


#2

Only difference i have with my code that works is that i used %s instead of %d.


#3

You should get used to spacing your statements to make it easy to read.


#4

Have you got your indentations right?


#5

I have the similar problem :
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 x in prices:
print x
print "Prices: %s" % prices[x]
print "Stock: %s" % stock[x]


#6

You can't capitalize 'prices' or 'stock' or the code-checker will reject it.


#7

i got this same problem

make sure you put "price" not "prices"
make sure you put everything in lower case


#8

i have already posed the question separately.

i have gone thru my code again and again..the same error about"orange"

The problem here is that I am not able to move forward to the next lesson.

is there a way out to skip this since I have understood the concepts.


#9

It took me some time to figure out what was wrong with my oranges.
It finally worked after I removed all the s from "prices" words.

Have you tried it too?


#10

my code works fine with "%s" but it still throws an error
"Check what your code prints for orange. It doesn't look quite right!"


#11

Hi Can you post your code or creat a new Topic with your code and the error you get.


#12

It works! But I wonder why


#13

how ever i tried all the possibilities but can't finf any solution please go through my script

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


#14

Hi this part

print "prices:.....

you should remove the s from price
so it should be like that

print "price: %s" % prices[k]

#15

i have pbm with orange but i found answer

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


#16

thank you dat was really helpful


#17

thankyou that was really helpful


#18

price not prices. took me way longer than i would like to admit to figure out.


#19

Had the same problem, this worked! Thanks


#20

I think it's just the way Codecademy is evaluating the results. They want the answer to print as 'price' and not 'prices'. I'm not sure why the error asks to look at oranges though. I think if your coding it will work, because the results are the same (besides the 's'.)