MENU
Question -

Given a positive integer, write a function that computes the prime factors that can be multplied together to get back the same integer.



Answer -

def primeFactorization(num):
factors = [ ]
lastresult = num
# 1 is a special case
if num == 1:
return [ ]
while True:
if lastresult == 1:
break
c = 2
while True:
if lastresult % c = = 0:
break
c += 1
factors.append(c)
lastresult/= c
return factors

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×