8/13 what is wrong with my code?


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

It seems to print fine in the console but I keep getting the error message:
"Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)"


#2

I have and issue except mine tells me is that what my code prints for orange doesn't look quite right. Even though my code looks exactly like yours above. I had your error before I realized that I forgot to print the key.


#3

Same, here the code looks exactly the same. But get the same error ?


#4

Found the fix, it literally just involved a space in on the last line and indentations :confused:.
Doesn't change the out put of the code just makes it correct XD


#5
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]

#6

I have also realised that even if your code is correct unless you have the right indentations, you will get an error message.


#7

same issue, did u find the solution .. I do not have any indentation mistake


#8

The code above worked for me ^
Do you want to show yours and just compare it?


#9

Finally figured it out, that's what it is. Orange is changed to 1
prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1,
"pear" : 3
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15
}
for item in prices:
print item
print "price: %d" % prices[item]
print "stock: %d" % stock[item]


#10

it will give an error if you try to print 1.5 with a %d, i changed it to 15,and it worked! :smiley: