Count the total number of triangles after Nth operation | Function to return the total no . of Triangles ; For every subtriangle formed there are possibilities of generating ( curr * 3 ) + 2 ; Changing the curr value to Tri_count ;
def countTriangles ( n ) : NEW_LINE INDENT curr = 1 NEW_LINE Tri_count = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT Tri_count = ( curr * 3 ) + 2 NEW_LINE curr = Tri_count NEW_LINE DEDENT return Tri_count NEW_LINE DEDENT / * Driver code * / NEW_LINE n = 10 NEW_LINE print ( countTriangles ( n ) ) NEW_LINE