codescracker


python

Python Program to Find Factors of Number



« Previous Program Next Program »


Find Factors of Number in Python

To find factors of any number in python, you have to ask from user to enter a number to find and print all the factors of that number on the output screen as shown in the program given here.

Python Programming Code to Find Factors of Number

Following python program ask from user to enter a number to find factors of that number:

# Python Program - Find Factors of Number
		
while True:
	print("Enter 'x' for exit.")
	num = input("Enter a number: ")
	if num == 'x':
		break
	else:
		number = int(num)
		for i in range(2, number-1):
			if number%i == 0:
				print(i)
				i += 1

Here is the sample run of the above Python program shows how to find factors of any number:

python find factors of number

« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test