Skip to content
Home » Find Factors of Number using Function in Python

Find Factors of Number using Function in Python

Learn about Find Factors of Number using Function in Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Find Factors of Number using Function in Python

The below code finds the factors of a given number using a user-defined function.

# Python program to find factors of a number using function

 #user-defined function
def find_factors(num): 
   print('The factors of', num,'are:')
   for i in range(1, num + 1):
       if num % i == 0:
           print(i, end=' ')

# input number
num = int(input('Enter number: '))

# function call
find_factors(num)

Output:

Enter number: 8
The factors of 8 are: 1 2 4 8

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Find Factors of a Number using While Loop in Python