creates a 4x4 2D array named my_2d_array containing strings, initialises an empty string variable named diagonal1 to store the concatenated elements along the main diagonal of the 2D array, the outer for row in range(len(my_2d_array)) loop iterates through the rows of the 2D array, the inner for col in range(len(my_2d_array[row])) loop iterates through the columns within each row, checks if the current row index is equal to the current col index. In which case, we have a diagonal, appends (concatenates) the string value at my_2d_array[row, col] to the diagonal1 string, prints the concatenated elements along the main diagonal by displaying the content of the diagonal1 variable.

SDD Implementation - 2D arrays (Describing Code 3)

Leaderboard

Visual style

Options

Switch template

Continue editing: ?