Python Program - Find the Factors of a Number

www.igi‮.aeditf‬com

here's a Python program that finds the factors of a given number:

n = int(input("Enter a number: "))

factors = []
for i in range(1, n+1):
    if n % i == 0:
        factors.append(i)

print("Factors of", n, "are:", factors)

In this program, we first use the input() function to get a number from the user, and store it in the variable n.

We then create an empty list called factors.

We then use a for loop to iterate over all the numbers from 1 to n. For each number i, we check if n is divisible by i. If it is, then i is a factor of n, so we append it to the factors list.

Finally, we use the print() function to print out the factors of the number. Note that the factors will be printed in ascending order.