Something of Value: supposedly correct, but don't know why


#1

I was 99% sure my code was wrong for this section, and indeed what is outputted was very strange, but supposedly the section was completed successfully:

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

CONSOLE

orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
1.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.51.5
333333333333333
444444

117.0
None

Why would it consider this flawed code correct?


#2

The SCT is not perfect, and in many cases, flawed owing to not having examined edge cases, etc. It can be quite narrow in focus and only look for a certain element to be present in the code, and pass on that basis, even if the code is flawed. In other words, don't put too much stock (pun not intended) in the SCT. Trust your intuition and rely upon the compiler errors in the console for guidance through the syntax and technical errors.

This bit of code outputs as expected:

total = 0
for key in prices:
    print "%s: %.2f" % (key, prices[key] * stock[key])
    total += prices[key] * stock[key]
print total

#3

Thanks for the help and advice!