I have a simple Python script that recursively checks if number ranges are number nfactors x. If any of the numbers is not a factor, I return False, otherwise, when n==1I would like to return True. However, I keep coming back NoneTypeand I will be grateful for suggestions on how to fix this.
def recursive_factor_test(x, n):
if n==1:
return True
else:
if x % n == 0:
recursive_factor_test(x,n-1)
else:
return False
print recursive_factor_test(5041,7)
>>False
print recursive_factor_test(5040,7)
>>None
type(recursive_factor_test(5040,7))
>>NoneType
source
share