def insert_at_nth_column_of_matrix(column_vector, M, column_num):
    """
    Inserts a new column into an existing matrix
        :param column_vector: The column vector to insert
            IF a value is passed in, a column is created
            with all elements equal to the value
        :param M: The matrix to insert the new column into
        :param column_num: The column index to insert at
            NOTE: index is "zero" based

        :return: The altered matrix
    """
    # Section 1: Obtain matrix dimensions
    rows = len(M); cols = len(M[0])

    # Section 2: If a value has been passed in for column vector ...
    if not isinstance(column_vector,list):
        column_value = column_vector
        column_vector = [] # ... create a column vector ...
        for i in range(rows): # ... full of that value
            column_vector.append([column_value]) 

    # Section 3: IF column vector received, check for correct rows
    if rows != len(column_vector):
        raise ArithmeticError('Column and Matrix rows do NOT match.')

    # Section 4: Insert the column vector values one row at a time
    for i in range(rows):
        M[i].insert(column_num,column_vector[i][0])

    return M