for j in range(5):
for i in range(5):
if i < j:
print(0,end=' ')
elif i > j:
print(0,end=' ')
elif i < j:
print(0,end=' ')
else:
print(1,end=' ')
print()
>>> def f(n):
... for i in range(n):
... for j in range(n):
... if i == j or n - 1 - i == j:
... print(' 1', end='')
... else:
... print(' 0', end='')
... if j == n - 1:
... print()
...
>>> f(5)
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
>>> f(11)
1 0 0 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 1 0 0 0 1 0 0 0
0 0 1 0 0 0 0 0 1 0 0
0 1 0 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 0 0 1
>>>