I don't think I got a wrong answer, so what' up with the code?



Oops, try again. It looks like your code did not print the correct total.

I want to know why the compiler said that I had a wrong answer and how to correct it.

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]
    print " "
total = 0.0
for key in prices:
    print " %s" % (prices[key]*stock[key] )
    total = total +( prices[key]*stock[key])
print "total: %s" % total


They don't want

total: 4.5

they just want


So just remove "total: %s" % in your last print statement.


Coooool, I did it !
Thank you very much ! The compiler is not as smart as I thought aha...


It's not really about how the compiler is not smart but rather Codecademy use test cases (scripts) to see whether you were following the instructions in order to pass the lesson.

If you use your code anywhere else, you won't get such error.


Yes, you're right.
Thank you for your help!


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