Program to print the pattern 1020304017018019020 * * 50607014015016 * * * * 809012013 * * * * * * 10011. . . | Function to find the sum of N integers from 1 to N ; Function to print the given pattern ; Iterate over [ 0 , N - 1 ] ; Sub - Pattern - 1 ; Sub - Pattern - 2 ; Count the number of element in rows and sub - pattern 2 and 3 will have same rows ; Increment Val to print the series 1 , 2 , 3 , 4 , 5 ... ; Finally , add the ( N - 1 ) th element i . e . , 5 and increment it by 1 ; Initial is used to give the initial value of the row in Sub - Pattern 3 ; Sub - Pattern 3 ; Skip printing zero at the last ; Given N ; Function call
def sum ( n ) : NEW_LINE INDENT return n * ( n - 1 ) // 2 NEW_LINE DEDENT def BSpattern ( N ) : NEW_LINE INDENT Val = 0 NEW_LINE Pthree = 0 , NEW_LINE cnt = 0 NEW_LINE initial = - 1 NEW_LINE s = " * * " NEW_LINE for i in range ( N ) : NEW_LINE INDENT cnt = 0 NEW_LINE if ( i > 0 ) : NEW_LINE INDENT print ( s , end = " " ) NEW_LINE s += " * * " NEW_LINE DEDENT for j in range ( i , N ) : NEW_LINE INDENT if ( i > 0 ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT Val += 1 NEW_LINE print ( Val , end = " " ) NEW_LINE print ( 0 , end = " " ) NEW_LINE DEDENT if ( i == 0 ) : NEW_LINE INDENT Sumbeforelast = sum ( Val ) * 2 NEW_LINE Pthree = Val + Sumbeforelast + 1 NEW_LINE initial = Pthree NEW_LINE DEDENT initial = initial - cnt NEW_LINE Pthree = initial NEW_LINE for k in range ( i , N ) : NEW_LINE INDENT print ( Pthree , end = " " ) NEW_LINE Pthree += 1 NEW_LINE if ( k != N - 1 ) : NEW_LINE INDENT print ( 0 , end = " " ) NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT DEDENT N = 5 NEW_LINE BSpattern ( N ) NEW_LINE