The following Python program for prime factorization does not work -


i relatively new python. now, know there tons of better programs prime factorization out there tried writing code without , got stuck. here code:

def is_prime(n):     =2     while i<n:         if n%i==0:             return false         i+=1     return true def prime_factor(n):     b = n     factor=[]     = 2     while i<b , is_prime(i):         while n%i ==0:             factor.append(i)             n/=i             continue         i+=1     return factor print (prime_factor(28)) 

the code works numbers (27, 24, 12, 18 etc) fails 28. output [2,2] value 28. fault lie?

problem in while condition:

while i<b :     while is_prime(i) , n%i ==0:         factor.append(i)         n/=i         continue     i+=1 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -