[Python] Built-in module to calculate the least common multiple

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently using a function that accepts two numbers and uses a loop to find the least common multiple of those numbers,

    def lcm(x, y):
    """This function takes two
    integers and returns the L.C.M."""

    # Choose the greater number
    if x > y:
    greater = x
    else:
    greater = y

    while(True):
    if((greater % x == 0) and (greater % y == 0)):
    lcm = greater
    break
    greater += 1

    return lcm


    Is there a built-in module in Python that does it instead of writing a custom function?

    Continue reading...

Compartilhe esta Página