def is_prime Is prime number while if return False return True def fac

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def is_prime(x):
"""Is x a prime number?"""
i = 2
while i <= x / 2:
if x % i == 0:
return False
i += 1
return True
def factorize(x):
"""Returns list of prime multiplicators."""
if is_prime(x):
return [x]
else:
result = []
i = 2
while i <= x:
if x % i == 0:
nums = factorize(i)
for num in nums:
result.append(num)
x /= num
i = 1
i += 1
return result
number = int(raw_input("Enter factorizing number: "))
fact = factorize(number)
fact.sort()
print len(fact), "numbers"
print number, "=",
for i in fact[:len(fact) - 1]:
print i, "*",
print fact[len(fact) - 1]