Write a Python Program to Find the Factors of a Number

Finding the factors of a number is a common mathematical problem that arises in various areas of computer science and engineering.

In this tutorial, we will be discussing how to write a Python program to find the factors of a given number.


A factor of a number is a positive integer that divides the number without any remainder.

For example, the factors of 10 are 1, 2, 5, and 10.

To find the factors of a number, we can use a simple algorithm that checks all numbers from 1 to the given number and divides the number by each of them.

If the remainder is 0, then the divisor is a factor of the number.

Here is the Python program that implements this algorithm:

def find_factors(num):
    factors = []
    for i in range(1, num + 1):
        if num %% i == 0:
            factors.append(i)
    return factors

# Test the function
num = 10
print("Factors of", num, "are:", find_factors(num))

In this program, we first define a function called find_factors that takes a single argument num.

The function initializes an empty list factors that will store all the factors of the number.

Next, we loop through all numbers from 1 to num using the range function.

For each number, we check if the remainder of dividing num by the number is 0 using the modulo operator %.

If the remainder is 0, then the number is a factor of num, and we append it to the factors list using the append method.

Finally, we return the factors list that contains all the factors of the number.

To test the function, we set num to 10 and print the factors of 10 using the find_factors function.

The output of the program will be:

Factors of 10 are: [1, 2, 5, 10]

This confirms that the program correctly found all the factors of 10.


In conclusion, finding the factors of a number is a simple problem that can be solved using a straightforward algorithm in Python.

By implementing this algorithm in Python, we can easily find the factors of any number and use them for various mathematical and computational purposes.