Python Program to Print Factors of a Number

Python Program to Print Factors of a Number

In this article, we will be solving question based on Iteration and basic mathematical operation with Python. According to the question we have to print factors of a number.

If you like the article content, then share it in your coding groups so that more people can take advantage of the content. So, without wasting any time let's solve this question.

Question - Write a Python Program to Print Factors of a Number

Python Program to Print Factors of a Number


Logic and Explanation

Question - Write a Python Program to Print Factors of a Number

Python Program to Print Factors of a Number - In this program we have to find the factors of a number and print them on the screen. So, firstly we will input the number from the user whose factors he want to print.

n = int(input("Enter a Number"))


Now, as you know that if one number completely divides another number i.e. with remainder zero is known as the factor of that number. Similarly, we will iterate through all the numbers from zero to the given number and will divide the given number with all the numbers one by one. When we will get the remainder zero in the loop, we will print that number as it will be the factor of that number.

Here's the logic for the same.

for x in range(1,n+1):
    if n%x == 0:
        print(x)


Note - % is the modulus operator which returns the remainder.

So, I hope you liked the article and you would have found the content of the article useful and helpful for you. Share this article in your coding communities so that more people can take advantage of the content. Also, In case of any doubt feel free to ask in the comments below.

For More Such Python Programs - Click Here

Enjoy Coding!!!


Also Read :-

Extract Phone Number Details Using Python





For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment

For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.

Post a Comment (0)

Previous Post Next Post