To find all the factors of a certain number in python, we can use a loop to iterate through all the possible factors. A factor is a number that can divide the given number without leaving a remainder. We start the loop from 1 and go till the given number. If any number completely divides the given number, then it is a factor of the given number. Here's the code:
main.py373 chars18 lines
We can then call this function and pass the number as the argument. The function will return a list of all the factors of the given number. For example, let's find all the factors of 36:
main.py59 chars3 lines
This means that 1, 2, 3, 4, 6, 9, 12, 18 and 36 are all factors of 36.
gistlibby LogSnag