Skip to main content

Posts

Showing posts with the label The Crazy Programmer Python Program to Find Prime Factors of a Number Python Program to Find Prime Factors of a Number The Crazy Programmer

Python Program to Find Prime Factors of a Number Gorakh Gupta The Crazy Programmer

If a number p is fully divisible by another number q, then q is said to be a factor of p. Here q will be greater than 1 and less than or equal to p. So, if a number p is fully divisible by another number q and q is a prime number then q is said to be a prime factor of p. Prime numbers are those numbers that are only divisible by 1 and themselves. In this article, we will see the code to find the prime factors of a number. For example: If we take 5, then prime factors will be: 5 = 5 5 is the only prime factor of 5. If we take 20, then prime factors will be: 20 = 2 * 2 * 5 If we take 210, then prime factors will be: 210 = 2 * 3 * 5 * 7 Now let’s see the code of this problem. In this code, we will be creating two functions. The first function will help us to know if a number is prime or not. And the second function will help us to print the prime factor of a number. def isPrime(n): """ Function to return if a number is prime or not Input : A Number