My Python code is correct but it is showing it as wrong


#1

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


#2

OK I got it. Actually I was printing price and stock as int because in example it was in orange colour. Using %s did the job.


#3

I'm having the same problem. It says there is a problem with my 'orange' output. My code is below:

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

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

for a in prices:
print a
print "Price: %s" % prices[a]
print "Stock: %s" % stock[a]

Any ideas??


#4

I'm having the same issue.
The error message says:
Check what your code prints for orange. It doesn't look quite right!

my code 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 "Price: %s" % prices[key]
print "Stock: %s" % stock[key]

The output is:
orange
Price: 1.5
Stock: 32
pear
Price: 3
Stock: 15
banana
Price: 4
Stock: 6
apple
Price: 2
Stock: 0
None


#5

@cjcloud: Check the instructions below and see how you're supposed to print those values.

apple
price: 2
stock: 0

Even though your code is correct, the instructions must be followed so you can pass.


#6

I got it! I changed the P and S in Price and Stock to lower case and it now works.


#7

Thank you... it works now.


#8

No problem! Glad to help!


#9

I have the same problem even without upper case letters..Can someone please help?


#10

Exactly the same problem. Thanks!

Luca


#11

I have the same problem, but mine one are all lower case, and it still cannot pass.
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]

output is

orange
prices: 1.5
stock: 32
pear
prices: 3
stock: 15
banana
prices: 4
stock: 6
apple
prices: 2
stock: 0
None

But still have the message "Check what your code prints for orange. It doesn't look quite right!"

Can anyone see any problems. thanks


#12

Ok, I found my problem, it is the "s" after price