Prime factorization - list

前端 未结 17 842
说谎
说谎 2020-11-27 05:06

I am trying to implement a function primeFac() that takes as input a positive integer n and returns a list containing all the numbers in the prime

17条回答
  •  再見小時候
    2020-11-27 05:19

    I would like to share my code for finding the prime factors of number given input by the user:

    a = int(input("Enter a number: "))
    
    def prime(a):
        b = list()
        i = 1
        while i<=a:
            if a%i ==0 and i!=1 and i!=a:
                b.append(i)
            i+=1
        return b
    
    c = list()
    for x in prime(a):
        if len(prime(x)) == 0:
            c.append(x)
    
    print(c)
    

提交回复
热议问题