I have this Python project to draw tessellated triangles on the screen. It takes the height to form the size of the triangle, cols to specify how many triangles on a line, and rows which is how many lines it outputs.This program has taken me some time to put together and I'm not sure if this is the best way to do this. The first line is just the normal triangle, the second line and every other line after however only should show half of the triangle on the first and last column.Here's my .py file:import sysprint(make sure shell in full screen so the triangles are viewed properly... or disable word wrap :))height          = int(input(height))cols            = int(input(cols))rows            = int(input(rows))MAX_PAGE_WIDTH = 19 * 8width = height * 2 - 1if((width * cols) > MAX_PAGE_WIDTH):    print(Triangles not gonna fit on page, please enter smaller params... :/)    sys.exit()def get_even_number(num):    return num % 2 == 0triangle        = for column_row in range(rows):    half_space      = height - 1    stars           = 1    for row_of_triangle in range(height):        if(get_even_number(column_row)):            for column in range(cols):                triangle +=   * (half_space + 1) + * * stars +   * half_space        else:            for column in range(cols + 1):                if(not(column == 0)):                    triangle +=   * (half_space + 1)                if(column == 0 or column >= cols):                    sub = row_of_triangle                    if(column >= cols):                        sub += 1                    triangle += * * (stars - sub)                else:                    triangle += * * stars                if(column < cols):                    triangle +=   * half_space        half_space      -= 1        stars           += 2        triangle        += \nprint(triangle)Here is some sample output:input: height: 6 cols: 6 rows: 4      *           *           *           *           *           *     ***         ***         ***         ***         ***         ***    *****       *****       *****       *****       *****       *****   *******     *******     *******     *******     *******     *******  *********   *********   *********   *********   *********   ********* *********** *********** *********** *********** *********** ************           *           *           *           *           *     **         ***         ***         ***         ***         ***         ****       *****       *****       *****       *****       *****       ******     *******     *******     *******     *******     *******     ********   *********   *********   *********   *********   *********   ********** *********** *********** *********** *********** *********** *****      *           *           *           *           *           *     ***         ***         ***         ***         ***         ***    *****       *****       *****       *****       *****       *****   *******     *******     *******     *******     *******     *******  *********   *********   *********   *********   *********   ********* *********** *********** *********** *********** *********** ************           *           *           *           *           *     **         ***         ***         ***         ***         ***         ****       *****       *****       *****       *****       *****       ******     *******     *******     *******     *******     *******     ********   *********   *********   *********   *********   *********   ********** *********** *********** *********** *********** *********** *****
Triangle Tessellation Project
python;python 3.x;ascii art
I decided to approach the problem bottom-up.I see the problem as deciding how many asterisks and spaces should go on each line and in which order.This action of alternateing spaces and asterisks looks like a fundamental action building block of this program so it should be written in its own function.def alternate(a, b, start, start_length, a_length, b_length, times):        >>> alternate(A, B, C, 3, 2, 4, 3)    CCCBBBBAABBBB        return start * start_length + ''.join(thing * length        for thing, length in islice(cycle( ((b,b_length), (a,a_length))), times))Using this function is now easy, we just need to understand how asterisks, spaces, and starting spaces change. We can deduce that simply by doing simple cases by hand and counting, or if we are lucky by looking at the output required or given by an equivalent program:def make_triangles(height, cols, rows):        >>>     print(make_triangles(6, 6, 4))          *           *           *                    ***         ***         ***                 *****       *****       *****              *******     *******     *******           *********   *********   *********        *********** *********** ***********        return '\n'.join(alternate(' ', '*', ' ', start_space_length, space_length, asterisk_length, cols)            for (start_space_length, asterisk_length, space_length)             in zip(range(height, 0, -1), range(1, height*2, 2), range(height*2-1, 0, -2)))Using this code to make the odd lines is also easy.Concatenate a required number of even and odd lines to build the complete output.I suggest this method because it is logical and conceptually readable from looking at the code. Your code had myself lost over all the top-level variables and conditions leaving me without understanding how each step was correlated to the overall algorithm.Also the alternate function is now written and documented by a test, and it may prove useful in other similar ASCII art challenges allowing code re-use.