A day at the supermarket



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

for i in prices:
    print i
    print "prices: %s" %prices[i]
    print "stock: %s" %stock[i]


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

"price: %s" not"prices: %s"

Another thing..
If inside your code you commented out any code that includes print statement , It will give you same error so delete all commented code then try to run it.


It is possible that the code checker is checking spelling even for literals eg. while printing a sub-heading "price" the system checks whether it is "price" as defined in the system. Since it is looking for "price" to be output, "prices" or even "Price" (i.e. an upper case "p") is being considered by the system as WRONG!! The output in the console comes out correctly as expected without any syntax error.


OMG that is the stupidest thing ever..... took me hours to find that out



type or paste code here
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]

I am getting error "Check what your code prints for orange. It doesn't look quite right!"
My output is:
price: 1.5
stock: 32
price: 3
stock: 15
price: 4
stock: 6
price: 2
stock: 0
What's the mistake?
I have tried print "price: %d " % prices[key], also.


Well, I used str():

and it worked. But I don't understand, why the initial code is wrong.


Posting working code may lead to cheating(copy paste by others) (edit your working code)
Tho lets find why your last code did not worked?

Notice that space? (i've marked it)
That's your bug!


Oh, thanks @greentreemee :slight_smile:


I've got the same error and I don't know what's wrong with the code. Where did you used str() @payalanand ?


I'm guessing it's because you have %stock[key] instead of % stock[key].


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.