5
n
の数値が数値の因数であるかどうかを再帰的にチェックする単純なPythonスクリプトがあります。x
です。数字のいずれかが要因でない場合はFalse
、それ以外の場合はn==1
を返信します。True
です。しかし、私はNoneType
を返信し続け、これを修正する方法についての提案をいただきたいと思います。私は 'True'と期待していますが、 'None'を取得します
#Function
def recursive_factor_test(x, n):
if n==1:
return True
else:
if x % n == 0:
#print "passed {}".format(n)
recursive_factor_test(x,n-1)
else:
return False
#Example Expecting False
print recursive_factor_test(5041,7)
>>False
#Example Expecting True
print recursive_factor_test(5040,7)
>>None
type(recursive_factor_test(5040,7))
>>NoneType