a hexagonal number sequence is a sequence of figurate numbers where the nth hexagonal number h is the number of distinct dots in a pattern of dots consisting of the outlines of regular hexagons with sides up to n dots when the hexagons are overlaid so that they share one vertex calculates the hexagonal numbers sequence with a formula h n2n1 where h is nth element of the sequence n is the number of element in the sequence referencehexagonal number wikipedia https en wikipedia orgwikihexagonalnumber param len max number of elements type len int return hexagonal numbers as a list tests hexagonalnumbers10 0 1 6 15 28 45 66 91 120 153 hexagonalnumbers5 0 1 6 15 28 hexagonalnumbers0 traceback most recent call last valueerror length must be a positive integer param len max number of elements type len int return hexagonal numbers as a list tests hexagonal_numbers 10 0 1 6 15 28 45 66 91 120 153 hexagonal_numbers 5 0 1 6 15 28 hexagonal_numbers 0 traceback most recent call last valueerror length must be a positive integer
def hexagonal_numbers(length: int) -> list[int]:
    

    if length <= 0 or not isinstance(length, int):
        raise ValueError("Length must be a positive integer.")
    return [n * (2 * n - 1) for n in range(length)]


if __name__ == "__main__":
    print(hexagonal_numbers(length=5))
    print(hexagonal_numbers(length=10))