This is a Python Program to compute prime factors of an integer.
The program takes a number and computes the prime factors of the integer.
1. Take the value of the integer and store in a variable.
2. Using a while loop, first obtain the factors of the number.
3. Using another while loop within the previous one, compute if the factors are prime or not.
4. Exit.
Here is source code of the Python Program to compute prime factors of an integer. The program output is also shown below.
n=int(input("Enter an integer:")) print("Factors are:") i=1 while(i<=n): k=0 if(n%i==0): j=1 while(j<=i): if(i%j==0): k=k+1 j=j+1 if(k==2): print(i) i=i+1
1. User must first enter the value and store it in a variable.
2. The while loop is used and the factors of the integer are computed by using the modulus operator and checking if the remainder of the number divided by i is 0.
3. Then the factors of the integer are then again checked if the factor is prime or not.
4. If the factor of the integer has two factors, the factor is prime.
5. The prime factor of the integer is printed.
Case 1: Enter an integer:25 Factors are: 5 Case 2: Enter an integer:200 Factors are: 2 5
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Practice Programming MCQs
- Check Information Technology Books
- Apply for Programming Internship
- Apply for Python Internship
- Check Python Books