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


#1


https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/1/4?curriculum_id=4f89dab3d788890003000096

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


#2

They don't want

total: 4.5

they just want

4.5

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


#3

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


#4

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.


#5

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


#6

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