8/13 What is wrong with the orange?


#1

This is 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 "prices: %s" % prices[key]
print "stock: %s" % stock[key]

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

I don't know what is wrong, please someone can help me?


#2

Hey.

Plase use code tags so we can properly read you code. Thanks.


I stuck on 5/13, please help me
#4

I also ran into this problem and it kept saying I had problems with orange. Then I made sure all of the output formatting was identicaly to how the instructions wanted it. It ended up being simply string formatting in the for loop.

for key in prices:
indent preformatted text by 4 spacesprint key
indent preformatted text by 4 spacesprint "price: %s" % prices[key]
indent preformatted text by 4 spacesprint "stock: %s" % stock[key]

I originally had Price: and Stock: strings as uppercase for the first letter. I then changed it to lower case- price and stock, and immediately the oranges error went away.

In your sample code try changing "print prices:" to "print price:"


#5

I had this problem too, it turns out, it didn't want you to just print out the data, it also wanted you to print the "price:", and the "stock:".
Try this:

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

Hope this helps!


#6

prices = {
"banana":4,
"maca":2,
"laranja":1.5,
"pera": 4
}

stock = {
"banana": 6,
"maca": 0,
"laranja": 32,
"pera": 16
}
for key in prices:
print key
print "Prices:%s" % prices[key]
print "Stock:%s" % stock[key]

Oops, tente outra vez. Verifique o que seu codigo exibe para pera. Isso nao parece estar certo!

QUAL O ERRO????


#7

I had the same problem, and this fixed it. Just seems to be a case issue.


#8

This issue has fixed,just modify string "prices" to "price", then it works(?


#9

lol I was trying everything people said. My first issue was missing the PRINT KEY part but then it was literally just changes "prices" to "price" and it worked. I kept reading "prices" thinking the wording was awkward but it was exactly what the instructions said to use.

Really stupid.


#10

ok so i used 'price' instead of 'prices' and made sure it was all lowercase and it still gave me the orange thing!


#11

It expects accurate indentation.So there must be a space after ":" in
print "price: %s" %prices[key] .That worked for me.The correct code thereby is:

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


#12

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

%s means display for string. Though this may not solve the problem but once you read your code it means that you want to print a string but if you check your stock dictionary it is integer. :smile:


#13

HI, I had the same issue you did. Change "prices" to "price"


#14

use
print "price: %s" % prices[key]


#15

use this code for apple thing
for key in price:
if(price[key] == 2):
print key


#17

Had this same issue, changed prices to price and it worked! Thanks!


#18

write "price" instead of "prices" Like this:

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]


#19

change the value of orange 1,5 to 1.


#20

Hey @ficorc, I had the exact same problem. Out of sheer frustration, I just changed one of the "%s" to a different letter, like "%d", and that somehow miraculously worked. So, instead of having "%s" for both prints, do it like this:

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

Hope this helped!


#21

my code did work

had a trouble too. Use my code to pass it:

price = {

"apple": 2,

}
stock = {

"apple": 0,

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


#22

Even am facing the same problem...
Here's 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 "price : %d" %prices[x]
print "stock : %d" %stock[x]