Learn about Prime Factorization Python Program using Function in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Prime Factorization Python Program using Function
# Program to find prime factors of a number using function
#function
def primeNumber(num):
# find prime factors
for i in range(2, num + 1):
if(num % i == 0):
isPrime = 1
for j in range(2, (i //2 + 1)):
if(i % j == 0):
isPrime = 0
break
if (isPrime == 1):
print(i,end=' ')
print('are the prime factors of number',num)
# input from user
num = int(input('Enter number: '))
#function call
primeNumber(num)
Output:
Enter number: 6
2 3 are the prime factors of number 6
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Prime Factors Program using While Loop in Python