Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

Python Program to Find the Factors of a Number

1 min read

The factor of any number is a whole number which exactly divides the number into a whole number without leaving any remainder.

For example, 3 is a factor of 9 because 3 divides 9 evenly leaving no remainder.

Problem

Create a Python program to find all the factors of a number.

Algorithm

Step 1:  Take a number

Step 2: Loop over every number from 1 to the given number

Step 3: If the loop iterator evenly divides  the provided number i.e. number % i == 0 print it.

Program

number = 69
print("The factors of {} are,".format(number))
for i in range(1,number+1):
    if number % i == 0:
        print(i)

Output

The factors of 69 are,132369
number = int(input("Enter a number "))
print("The factors of {} are,".format(number))

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

Output

Enter a number  469
The factors of 469 are,1767469


PROGRAMS

Latest Articles

Latest from djangocentral

How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…
Read more →

4 min read

DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access serializer.data, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…
Read more →

3 min read

Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …
Read more →

5 min read

How to Perform NOT Queries in Django ORM

In Django, performing NOT queries allows you to exclude certain records from the query results based on specific conditions. The NOT operator, represented by the tilde (~) when used in conjunction with the Django ORM's Q object, helps you construct compl…
Read more →

3 min read