Python Prime Factors Program – This Python program will take a number as input from the user. It will display prime factors of that number.
We will study prime factors before writing the Python program to find them.
Definition of Prime Factor
A factor that is a prime number is called a Prime Factor.
We can say that prime factors are any set of prime numbers that will give the original number when multiplied.
Example: Find prime factors of 15
The prime factors of 15 are 3 and 5.
Note that 3 and 5 are prime numbers.
Question: Find prime factors of 15
The prime factors of 12 are 2, 2 and 3.
Note that 2, 2 and 3 are prime numbers.
Another Example: Find prime factors of 15
The prime factors of 35 are 5 and 7.
Note that 5 and 7 are prime numbers.
Python Programming Constructs Used in this Program
- User Defined functions in Python. No doubt the use of user defined functions reduce the code complexity and improves code reuse.
- Python if else statement Two way Selection – Python if else statement
- while loop in Python programming language The Python while loop Syntax, Flowchart, Working, with Real World Examples
- print() function Python print function – Printing Output
- Use of comments Explain the Use of Python Comments
- Python input function to Get Input from user at run time
Source Code of Python Prime Factors Program
Output of Python Prime factors Program
Enter a number to find Prime factors:12 The prime factors of 12 are: 2 2 3 (2) Enter a number to find Prime factors:60 The prime factors of 60 are: 2 2 3 5 (3) Enter a number to find Prime factors:35 The prime factors of 35 are: 5 7
This Python program explains the concept of prime factorization of a positive number with the help of definition and a lot of examples.
Moreover the code is quite easy to understand and simple to write. Keep visiting EasyCodebook.com for perfect Python programming tutorials to improve your programming logic.
2,116 total views, 3 views today