With detailed comments and explanation please in Python 3 Wr
With detailed comments and explanation please in Python 3
Write a function getListWithMOrMoreFactors(N, M) that returns a list of all the numbers between 1 and N inclusively that each have at least M factors. For example, getListWithMOrMoreFactors(12, 4) should return [6, 8, 10, 12].Solution
def n_factors(n):
c = int(n/2);
ans=0
for i in range(1,c+1):
if(n%i==0):
ans+=1
return ans+1
def getListWithMOrMoreFactors(N,M):
l=[]
for i in range(2,N+1):
if(n_factors(i)>=M):
l.append(i)
return l
c = getListWithMOrMoreFactors(12,4)
print(c)
