Finding factors of a number

A simple code to find the factors of a number using for loop

Welcome to the code! We will be using for loop to find the factors of the number which is input by the user. We define a function to print the factors.

Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!

							
							
					def print_factors(x):
   print("The factors of",x,"are:")
   for i in range(1, x + 1):
       if x % i == 0:
           print(i)

num = int(input("Enter the number for which you want to find factors: "))

print_factors(num)				
			
Share on facebook
Share on whatsapp
Share on pinterest
0 0 votes
Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments