generate functionSat, 12 Nov 2022

Return the prime factorization of an input number

# function: return prime factorization of input number def prime_factor(n): # creating an empty list to store prime factors prime_factors = [] # dividing values from 2 to the input number for i in range(2, n+1): # checking if the input number is divisible by the current number while n % i == 0: # if divisible, the current number is a prime factor of the input number prime_factors.append(i) # dividing the input number by the current number n /= i # returning the list of prime factors return prime_factors prime_factor(50)

Questions about programming?Chat with your personal AI assistant