8. Keeping Track of the Produce


#1

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

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

for n in price:
print n
print "Price: %d" % price[n]
print "stock: %d" % stock[n]

it is giving error like "Oops, try again. Check what your code prints for orange. It doesn't look quite right!"


#2

HI this line

print "Price: %d" % price[n]

this part

"Price:

Remove the uppercase P to price


#3

still getting error
i dont know why this is giving error like this


#4

so it's look like that ?

print "price: %d" % price[n]

if so try to change the %d with %s also to the other If it doesn't work can you post your new code?


#5

thanx buddy:slight_smile:


#6

Hi wizmarco.
My code seems to be correct in console but i have always the same problem:
"Oops, try again. Check what your code prints for orange. It doesn't look quite right!"
This is my code :

prix = { "banane": 4, "pomme": 2, "orange": 1.5, "poire": 3 }
stock = { "banane": 6, "pomme": 0, "orange": 32, "poire": 15 }
for key in prix:
print key
print "prix: %s" % prix[key]
print "stock: %s" % stock[key]

And in the console :

orange
prix: 1.5
stock: 32
banane
prix: 4
stock: 6
poire
prix: 3
stock: 15
pomme
prix: 2
stock: 0
None

That's why i don't understand.
Is it a bug ?


#7

Hi it's not a bug is just that in the french lesson you should print it like that

pomme
prix : 2
stock : 0

so here

print "prix: %s" % prix[key] 
print "stock: %s" % stock[key]

add a space before the :


#8

Thanks a lot.
it was just a question of space.
Finally it works.


#9

Hey folks! Thanks for sharing, but I still can't get mine to work, I'm unsure exactly where the flaw is.

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]


#10

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]

I'm still trying but the same error appears about orange not looking right.


#11

Hi this line

print "prices: %s" % prices[x]

this part

"prices:

you should remove the s to prices


#12

I have tried all the solutions but I still can't get mine to work. Can you please assist.

Thank you!

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


#13

Hi first this

print "prices:%d" % prices[x]

should be

print "price:%d" % prices[x]

then you should put a space after price: like that

print "price: %d" % prices[x]

#14

Thank you for the response.
I had figured out that its all about spacing and formating.

Here is the correct code I have written

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