How to access elements of a Square Matrix | Python3 Program to read a square matrix and print the Corner Elements ; Get the square matrix ; Display the matrix ; Print the Corner elements ; check for corner elements
if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT matrix = [ [ 0 for i in range ( 5 ) ] for j in range ( 5 ) ] NEW_LINE row_index , column_index , x , size = 0 , 0 , 0 , 5 ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT x += 1 ; NEW_LINE matrix [ row_index ] [ column_index ] = x ; NEW_LINE DEDENT DEDENT print ( " The ▁ matrix ▁ is " ) ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT print ( matrix [ row_index ] [ column_index ] , end = " TABSYMBOL " ) ; NEW_LINE DEDENT print ( " " ) ; NEW_LINE DEDENT print ( " Corner Elements are : " ) ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT if ( ( row_index == 0 or row_index == size - 1 ) and ( column_index == 0 or column_index == size - 1 ) ) : NEW_LINE INDENT print ( matrix [ row_index ] [ column_index ] , end = " TABSYMBOL " ) ; NEW_LINE DEDENT DEDENT DEDENT DEDENT