factorsofanumber1 1 factorsofanumber5 1 5 factorsofanumber24 1 2 3 4 6 8 12 24 factorsofanumber24 factors_of_a_number 1 1 factors_of_a_number 5 1 5 factors_of_a_number 24 1 2 3 4 6 8 12 24 factors_of_a_number 24 if i is a factor of num num i is the other factor of num if d and i are distinct we have found another factor
from doctest import testmod
from math import sqrt


def factors_of_a_number(num: int) -> list:
    
    facs: list[int] = []
    if num < 1:
        return facs
    facs.append(1)
    if num == 1:
        return facs
    facs.append(num)
    for i in range(2, int(sqrt(num)) + 1):
        if num % i == 0:  
            facs.append(i)
            d = num // i  
            if d != i:  
                facs.append(d)  
    facs.sort()
    return facs


if __name__ == "__main__":
    testmod(name="factors_of_a_number", verbose=True)