Error in 8/13


#1

hi there,
i have a trubles in getting thorugh the 8/13.
even though i get printed what is required in the istructions thy pyhton still says "
Oops, try again. Check what your code prints for orange. It doesn't look quite right!"

please help!
here 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]

#2

I had the same problem, all I did is change prices to price
price = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
for fruits in price:
print fruits
print "price: %s" % price[fruits]
print "stock: %s" % stock[fruits]


#3

Just change :

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

to :

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

#4

yeah, you was right, but why was that? I don't understand why just changed prices to price and it worked ?? :confused:


#5

CodeAcademy compare the strings you print with the ones it expects to determine if you passed or not. Any misspellings, missed punctuation etc. will cause this to fail. There is nothing really wrong with the code you wrote first, but you need to follow the instructions pretty strictly to pass some of the exercises.


#6

Thanks. That why I tested it on Python shell and it had no problem


#7

Thanks for your answer, I didn't thought that "s" behind the price.


#8

try this, it worked perfectly

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