# Prime factors of number

Finds and returns the list of prime factors of a number.

• Use a `while` loop to iterate over all possible prime factors, starting with `2`.
• If the current `factor` exactly divides `num`, add `factor` to the `factors` list and divide `num` by `factor`. Otherwise, increment `factor` by one.
```def prime_factors(num):
factors = []
factor = 2
while (num >= 2):
if (num % factor == 0):
factors.append(factor)
num = num / factor
else:
factor += 1
return factors

prime_factors(12) # [2,2,3]
prime_factors(42) # [2,3,7]```

## More like this

• Python ·

### Median

Finds the median of a list of numbers.

• Python ·

### Digitize number

Converts a number to a list of digits.

• Python ·

### Sum of powers

Returns the sum of the powers of all the numbers from `start` to `end` (both inclusive).

• Python ·

### Geometric progression

Initializes a list containing the numbers in the specified geometric progression range.

Start typing a keyphrase to see matching snippets.