how to find factors of a number wihtout using % 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 the factors of a number
def findFactors(num: int)->list:
factors=[]
for i in range(1,num+1):
if num%i==0:
factors.append(i)
return factors