Member-only story

Interview question: Use Python to determine the factors of a number

Crystal X
2 min readJul 13, 2023

--

If a person wants to become a Python developer, he needs to know the solutions to a variety of problems because he may be asked questions about them at a coding interview. One such question would be to find the factors of a number.

A factor is an integer that divides exactly into a whole number without a remainder, making it a whole number. In other words, a factor is a number that divides another number evenly, with no numbers left over in the division process.

The factors of a number can be found by systematically dividing the number of each counting number, starting with one.

The psuedocode for finding the factors of a number is:-

  1. Define the number that needs to be factored as num.
  2. Define an empty list that will hold the factors as factor_lst.
  3. Define a function, find_factors, which will find the factors of an input number, x.
  4. In the function, create a for loop that will iterate from 1 to x+1, if x modulus i equals zero then it is a factor and will be appended to the factor_lst.
  5. When the for loop completes its iterations, the function will return the list, factor_lst.

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet