Articles

# Python program to find prime factors of a number using for loop

In this python programming guide, we are going to learn

• write a python program to find the prime factors of a given number

### Program to find the factors of a number in Python

The program to find prime factors of a number in python is as follows:

``````# Owner : TutorialsInhand Author : Devjeet Roy

number = int(input("Enter a number: ").strip())

for i in range(1,number+1):
if number % i == 0:
print(i, end=" ")
``````

The output of python program to find prime factors of a number using for loop as follows:

``````PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a number: 35
1 5 7 35``````

1. We ask the user to enter a number and we convert it to integer type.

2. Then we run a loop from 1 to the number itself, to find the factors. Remember, 1 and the number itself is always a factor of the number.

Write a python program to find the prime factors of a given number snapshot:

Python Numbers Program

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com