Gen-AI Developer Classroom notes 18/Sep/2025

Python contd

Operators



def lcm(start:int =1, end:int =10) -> int:
    """Lcm of a sequence

    Args:
        start (int, optional): start value. Defaults to 1.
        end (int, optional): end value. Defaults to 10.

    Returns:
        int: lcm
    """
    factor = end * (end -1)
    max = factorial(end)
    result = 0
    # check if factor is divisible by all numbers in a sequence 
    # if not increment by factor
    while factor <= max:
        index = start
        is_lcm = True
        while index <= end:
            if factor % index !=0:
                is_lcm = False
                break
            index += 1
        if is_lcm:
            result = factor
            break
        factor += end * (end -1)
    return result

How Python deals with allocating memory

  • Python has two datatypes
    • mutable: values can be changed without allocating new memory location
    • immutable: every value change leads to a new memory location.
  • int,float,complex are immutable.
  • list is mutable

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading