I expect ‘True’ but get ‘None’ [duplicate]

You don’t ever return the return value of the recursive call:

if  x % n == 0:
    #print "passed {}".format(n)
    return recursive_factor_test(x,n-1)

When you omit the return statement there, your function ends without a return statement, thus falling back to the default None return value.

With the return there, it works:

>>> print recursive_factor_test(5040,7)
True

Leave a Comment