Keeping Track of the Produce


#1

Hi everyone!

.I have a problem with the error message I get...
So my code is good: but the error is which i dont understand: "You should have exactly three print statements..."' I don't understand the error cause the task was: " for each key, print out the key along with its price and stock information." And I did the task. But I think there is a bug in the codecademys checking background. or am I wrong?

My code and ouput is below

prices = {}
prices["banana"] = 4
prices["apple"] = 2
prices["orange"] = 1.5
prices["pear"] = 3
#print prices

stock = {}
stock["banana"] = 6
stock["apple"] = 0
stock["orange"] = 32
stock["pear"] = 15
#print stock

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


Output:
orange
price: 1.5
stock: 32

pear
price: 3
stock: 15

banana
price: 4
stock: 6

apple
price: 2
stock: 0

None

If I tried printing just the apple and its price and stock value then "None" printed out too (which I think is an automatic thing in codecadamy. And then I got the same error cause instead of 3 I had 4 print outs...

Thank you for your answers!

Anna


#2

None is normal behavior of the console and can be ignored. Your code looks correct and so does the output. I wonder if it has anything to do with the way you populate your dictionaries? Could the SCT be looking at?

Maybe try writing literal dictionaries?


#3

Thank you for your answers.

Whats SCT?

I tried it with this dict format:

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

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

And then I did:

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

Output

apple
price: 2
stock: 0
None

and cause of None it does'nt say it's correct, the error is the same...


#4

SCT => Submission Correctness Test

In your first attempt, the extra print statement might be causing a problem.

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

#5

Oh thank.
Ive tried and its the same

Output: without spaces between fruit types. and the error is the sama

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

#6

For who can I write to? so they change the SCT, cause I think the checker is wrong and it's bad luck that I can't move on to the next lesson/task.:(((


#7

I just passed with your code. Be sure you do not have any print statements (even in comments). The SCT is literally counting them.


#8

oh I had a print in a comment. thank you very much!!!


#9

2 posts were split to a new topic: Keeping track of produce - Someone please help find error


#10