Statement
Given an integer , produce a two-dimensional array of size and complete it according to the following rules, and print with a single space between characters:- On the main diagonal write
0
. - On the diagonals adjacent to the main, write
1
. - On the next adjacent diagonals write
2
and so forth.
Print the elements of the resulting array.
sample
n=7 | 0 1 2 3 4 5 6 1 0 1 2 3 4 5 2 1 0 1 2 3 4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 5 4 3 2 1 0 1 6 5 4 3 2 1 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n= int(input()) | |
b=[[abs(x-y) for x in range(n)]for y in range(n)] | |
for i in range(n): | |
for j in range(n): | |
print(b[i][j],end=" ") | |
print('\n') |
No comments:
Post a Comment