Computer Science, asked by 2005arnavmehta2005, 9 months ago

Can anyone explain this?

def primes(n):

primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d)
n //= d
d += 1
if n > 1:
primfac.append(n)
print(primfac)
print("\n")
while True:
num=int(input("ENTER THE NUMBER: "))
primes(num)​

Answers

Answered by pavithranatarajan855
1

Answer:

For loop we given the while True then it get a number from user and save it in  num then primes function called using num as a parameter now n=num.

Inside the function Emptylist is created using the name primfac.

d is initialized with 2.

d*d<=n condition will be checked

[reason :This program will return the factors of the n...we can only factorize the number which 4 or greater than 4]

% will give remainder if remainder 0 then n is divisible by d .so d is added into the list then n divided by d then d incremented and these steps continued until condition is false.

if n>1 for the n itself some times factors no other factors available so that time primfac contains n inside it.

Explanation:

This program will return factors of n.

Similar questions