Python练习题答案: 查找因素下到极限【难度:1级】--景越Python编程实例训练营,1000道上机题等你来挑战

查找因素下到极限【难度:1级】:

答案1:

def factors(integer, limit):
    return [x for x in range(limit,integer+1) if integer % x == 0]

答案2:

def factors(a, b):
    return [x for x in range(b, a + 1) if not a % x]

答案3:

def factors(integer, limit):
    list = [];
    if limit > integer:
        return list;
    for num in range(limit,integer+1):
         c1 = integer/num;
         c2 = integer//num;
         if c1 == c2:
            list.append(num);
    return list;

答案4:

factors=lambda n, l: [i for i in range(l,n+1) if not n%i]

答案5:

def factors(n, l):
    #Code Away
    return [] if l >n else sorted(i for i in list(set(sum([[i, n//i] for i in range(1, int(n**.5)+1) if not n%i], []))) if i>=l)

答案6:

def factors(integer, limit):
    return [i for i in range(limit, integer + 1) if integer % i == 0]

答案7:

def factors(integer, limit):
    #Code Away
    return [i for i in range(limit, integer+1) if integer % i == 0]

答案8:

def factors(i, limit):
    return [x for x in range(limit, i + 1) if not i % x]

答案9:

def factors(integer, limit):
    ret = [i for i in range(limit, integer + 1) if integer % i == 0]

    return ret​

答案10:

factors=lambda i,l:[x for x in range(1,i+1) if i%x==0 and x>=l]

答案11:

def factors(integer, limit):
    res = []
    for i in range(limit, integer + 1):
        if integer % i == 0:
            res.append(i)
    return res​




Python基础训练营景越Python基础训练营QQ群

在这里插入图片描述
欢迎各位同学加群讨论,一起学习,共同成长!

你可能感兴趣的:(Python编程进阶练习题)