Find the factorize value of a dividable number with python

In this short example we will show you how to find out the factorize value of a dividable number with python. In below program the divisible function will continue to call itself until the dividend is smaller than the divisor where at that moment the program will roll back and return the final factorize value of the dividend! We will use the python thread module in below program as well.

import threading

class diviableThread(threading.Thread):

    def __init__(self, divisor, dividend):
        threading.Thread.__init__(self)
        self.divisor = divisor  # the divisor
        self.dividend = dividend # the dividend
        self.outcome = 0

    def run(self):
        self.diviable = self.divisible(self.dividend)  # call the divisible function
        print("The factorize value of " + str(self.dividend) + " divide by " + str(self.divisor) + " is " + str(self.diviable))

    def divisible(self, n):
        if ((n//self.divisor) == 0):
            return self.outcome
        else:
            self.outcome = n//self.divisor
            return n * self.divisible(self.outcome)  # the function will repeatedly call itself until the base has been reached

if __name__ == "__main__":
    diviser = input("Enter the divisor : ")
    dividend = input('Enter the dividend: ')
    # Create new threads
    thread1 = diviableThread(int(divisor), int(dividend))
    # Start the thread
    thread1.start()

Below is one of the run which we have done with the above program.

python factorize
python factorize

The above program has been written with PyCharm, which is the famous IDE uses by many python developers to develop their project!

Like this post? Kindly share!