Sunday 18 September 2022

Python Example Program : Finding Factors

Finding all the possible factors of an integer in Python

Example

x=int(input("Enter a number to find all the possible factors: "))
y=[]
for i in range(1,x+1):
    if x%i == 0:
        y.append(i)
print(y)

Output

Enter a number to find all the possible factors: 400
[1, 2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 200, 400]

No comments:

Post a Comment