Python Challenge - Sum of Prime Factors

Ah thank you much. I now understand.

1 Like

Now the question is, ‘why did it work?’ This is an edge case that is a necessary forensic investigation concern.

1 Like

Oh. yes, because of count==2 condition since 1 only can be divided by its own without remainder, therefore, count = 1 for x value of 1.

1 Like

Not the cleanest but the first code i got to function properly

def sum_of_prime_factors(n):
lst = list(range(1,n+1))
factors =
for i in lst:
if n % i == 0:
factors.append(i)
primelst =
for i in factors:
check = True
for j in range(2,i):
if i % j == 0:
check = False
if check == True:
primelst.append(i)
total = 0
for i in primelst:
total = total + i
return total - 1

print(sum_of_prime_factors(91))

def sum_of_prime_factors(n):
x = 0
for i in range(2, n + 1):
if n % i == 0:
if n == i:
return i
else:
y = sum_of_prime_factors(n // i)
if i != y:
return i + y
return y

print(sum_of_prime_factors(91))