PYTHON Formation

0

Can you give me a hint how to print the following problem in the right 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 Online Judger URI - 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 in advance for the help!

    
asked by anonymous 19.06.2018 / 03:02

1 answer

0
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 pos, j in enumerate(i): # pos vai ser o endereço do valor j
        if pos == 0: # se for a primeira coluna pos = 0
            print('{:3}'.format(j), end='')
        else:
            print('{:4}'.format(j), end='')
    print('')
    
19.06.2018 / 19:00