When testing numbers some work for example 48, but others don't. I'm not sure what the best way to approach finding all the factors of a number.
Prime Factorization
def find_primes(n):
factors = []
i = 2
if n == 0:
return 0
if n == 1:
return 1
if n >= 2:
while n % i == 0:
next_n = n / i
factors.append(i)
n = next_n
if n % i != 0:
i += 1
continue
elif i == n:
break
if len(factors) == 0:
return "{} is a prime number.\n".format(initial_n)
else:
return "The prime factors of {} are: {}\n".format(initial_n, factors)
n = int(input("Enter a number to find all the Prime Factors:"))
initial_n = n
print('\n')
print(find_primes(n))
I am expecting to get a list of all the factors of a number.