Python Armstrong NumberPython Average of N NumbersPython Biggest of Three NumbersPython Common DivisorsPython Composite NumberPython Condense a NumberPython Even NumberPython Factorial of a NumberPython Fibonacci SeriesPython GCDPython LCMPython Leap YearPython Multiplication TablePython Number CombinationPython Odd NumberPython Palindrome NumberPython Perfect NumberPython Prime FactorPython Prime NumberPython Sum of DigitsPython Swapping Two Numbers

Python Array ProgramsPython Converter ProgramsPython Star Patterns ProgramPython Number Patterns ProgramPython Alphabet Patterns ProgramLast Updated:

A Prime Factors of a given number is that any prime number other than 1 and itself that exactly divides the given number. For example, the prime factors of 60 is 2, 3, 5

The following table provides few examples of prime factors of a number.

Number | Prime Factors |
---|---|

55 | 5, 11 |

100 | 2, 5 |

186 | 2, 3, 31 |

In the following example, we will find all the Prime factors of the given number (186).

Python Compiler

num = 186
flag = 0
for i in range(2, num):
if(num % i == 0):
count = 0
#Check for prime number
for j in range(1, i+1):
if(i % j == 0):
count += 1
if(count == 2):
if(flag == 0):
print("Prime factor of %d:" % num)
print(i, end=" ")
flag = 1
if(flag == 0):
print("There is no Prime factor for %d " % num)

In the following example, we will find a prime factors of any given number.

Python Compiler

num = int(input("Enter a (int) number: "))
flag = 0
for i in range(2, num):
if(num % i == 0):
count = 0
#Check for prime number
for j in range(1, i+1):
if(i % j == 0):
count += 1
if(count == 2):
if(flag == 0):
print("\nPrime factor of %d:" % num)
print(i, end=" ")
flag = 1
if(flag == 0):
print("There is no Prime factor for %d " % num)