0
can give me a hint on how to print the following problem in the correct way?
while True:
m = int(input())
mlen = m
sm = 1
aux = 1
matriz = []
if m == 0:
print()
break
for i in range(m):
linha = []
for j in range(m):
linha.append(sm)
matriz.append(linha)
while m - 2 > 0:
for i in range(aux, m - 1):
for j in range(aux, m - 1):
matriz[i][j] = sm + 1
sm += 1
aux += 1
m -= 1
for i in matriz:
for j in i:
print('{:4}'.format(j), end='')
print('')
I need the printed matrix to have 2 spaces on the left side, 3 spaces between the values and no space at the end of each line. It is an exercise of the URI Online Judge - 1435.
Accepted Output Your Output
1 ··1···1···1···1 1 ···1···1···1···1
2 ··1···2···2···1 2 ···1···2···2···1
3 ··1···2···2···1 3 ···1···2···2···1
4 ··1···1···1···1 4 ···1···1···1···1
6 ··1···1···1···1···1 6 ···1···1···1···1···1
7 ··1···2···2···2···1 7 ···1···2···2···2···1
8 ··1···2···3···2···1 8 ···1···2···3···2···1
9 ··1···2···2···2···1 9 ···1···2···2···2···1
10 ··1···1···1···1···1 10 ···1···1···1···1···1
Thanks for your help!
Edit your question and add the full statement of the exercise, too, as it will facilitate in understanding the issue.
– Woss
Note that the way you said what you need is not right. Values are right justified in size
3and separated by space. So if you have the number11, will have 1 space before due to justification and another to separate from the other elements.– Isac