Python find sum of prime factors without loop
<p>I'm trying to produce the sum of all prime factors of a number without using loop. However if the result of prime_factor(m, k) bigger than 2, when go to main(n) after factor=prime_factor(m, k), factor will be None</p>

<pre><code>def prime_factor(m, k):
    if m%k==0:
        return k 
    else:
        prime_factor(m, k+1)

def main(n):
    if n&lt;2:
        return 0
    if n==2:
        return n
    else:
        factor=prime_factor(n, 2)
        return factor+main(n//factor)
</code></pre>

<p>Your <code>prime_factor</code> function is not doing anything with the result of the recursive call. You need to return it:</p>

<pre><code>def prime_factor(m, k):
    if m%k==0:
        return k 
    else:
        return prime_factor(m, k+1)         # need the return here
</code></pre>

<p>Also minor optimization but you could adjust your values so you start at 3 and do prime_factor(m, k+2) in the recursive call instead of k+1.</p>

python recursion sieve-of-eratosthenes prime-factoring