0

whats wrong with this code

#!/usr/bin/python3 ##show prime factors of an intager #it's a function to check if the factor is prime #begin ---> def ifprime(n): if n<2: return False elif n==2: return True else: for m in range(2,n): if n%m==0: return False return True #it's a function to check if the factor is prime #<--- end #it's a function that give you an array of the prime factors of a number #begin ---> def factors(n): i=n arr=[] if ifprime(i): arr.append(i) else: while(i>1): for j in range(2,i): if ifprime(j): if i%j==0: arr.append(j) i=int(i/j) arr.sort() return arr #it's a function that give you an array of the prime factors of a number #<--- end #it's a function that make the prime factor string #begin ---> def makepfstr(factorsarr): s="" for i in factorsarr: s+="("+str(i)+")*" return s[:-1] #<--- end #it's a function that make the prime factor string i=int(input("Give me the number:")) print("i="+makepfstr(factors(i)))

31st Jul 2017, 3:38 AM
mohamad hosein khani cosar khizi
mohamad hosein khani cosar khizi - avatar
1 Antwort
+ 7
it's working correctly. but sometimes showing time limit exceeded problems that's when it takes too much time to run in sololearn's server. so code is correct it's working. nothing wrong in the code.
31st Jul 2017, 4:23 AM
Sandeep Chatterjee