Pass a number to a function as parameter which finds the factors of the given number and displays it. If a number is not given, then display with default value in python code example
Example 1: to find factors of a number in python
# Python Program to find the factors of a number
# This function computes the factor of the argument passed
def print_factors(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
num = 6
print_factors(num)
Example 2: python find factors of a number
def factors(n):
return set(reduce(list.__add__, \
([i, n