[Tutor] How to deal failed function and 0xDEADBEEF type errors...

Sean Carolan scarolan at gmail.com
Thu Jul 15 20:07:39 CEST 2010


Spoiler alert:  This was encountered while working on MIT OCW 6.000
problem set 4.

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/ps4.py


My function returns a list as it should:

##############################
def nestEggFixed(salary, save, growthRate, years):
    yearlyreturn=[]
    nut = 0
    for i in range(0, years):
        # print "At the end of year",(i),"nut size is:",(nut)
        nut = nut * (1 + 0.01 * growthRate) + (salary * save * 0.01)
        yearlyreturn.append(nut)
    return yearlyreturn
##############################

print nestEggFixed(10000, 10, 15, 5)
[1000.0, 2150.0, 3472.5, 4993.375, 6742.381249999999]

So far so good right?  Not so fast, the test function provided by the
instructors is failing:

Here's the test function:

##############################
def testNestEggFixed():
    salary     = 10000
    save       = 10
    growthRate = 15
    years      = 5
    savingsRecord = nestEggFixed(salary, save, growthRate, years)
    print savingsRecord
##############################

Run it by itself and there's no output:

testNestEggFixed

Try to print it and it throws this error:

print testNestEggFixed
<function testNestEggFixed at 0x0214D5F0>

What am I missing here?  I even tried running all the code in the test
function in my script and it works fine.  It only fails when it's put
into a function.  I think I must be doing something wrong.


More information about the Tutor mailing list