Here in this article, we have written a python code that asks the user to enter a number and print all the factors of that number as an output.

##
**
Prerequisite Python Program to Find the Factors of Number
**

- Python Input, Output
- Python Data types
- Python User-defined Functions
- Python Loop

####
**
Steps
**

- Create a user-defined function factor() that accepts a value as an argument.
- Create a for loop with a range from 1 to the number n+1.
- print all the numbers which can divide the function argument.

##
**
Python Program to Find the Factors of a Number
**

###
**
Python Code
**

```
def factor(num):
print("The factors of",num,"are:")
for i in range(1, num + 1):
if num % i == 0:
print(i)
num = int(input("Enter a Number: "))
factor(num)
```

**
Output 1:
**

```
Enter a Number: 200
The factors of 200 are:
1
2
4
5
8
10
20
25
40
50
100
200
```

**
Output 2:
**

```
Enter a Number: 40
The factors of 40 are:
1
2
4
5
8
10
20
40
```

**
People are also reading:
**

- Python Program to Find LCM
- WAP in using the switch case to print the Equivalent name of the day on the basis of user input
- Python Program to Convert Decimal to Binary, Octal and Hexadecimal
- WAP in C++ & Python for the Union of Two Arrays
- Python Program to Find Numbers Divisible by Another Number
- WAP to find quotient and remainder of two numbers
- C Program to Design Love Calculator
- WAP to calculate sum and average of three numbers
- C Program to Extract a Portion of String
- Python Program to Convert Kilometers to Miles

## Leave a Comment on this Post