Replace matrix elements with an "X"

Asked

Viewed 380 times

0

I have code that should print a matrix according to the input.

You should print the matrix so that the "X" forms a right spiral starting from the middle, someone has some idea?

ps.:Code comments are attempts

while True:
tamanho = int(input())
if tamanho in range(1, 25):
    tabela = []
    for x in range(0, tamanho):
        tabela.append(["O"]*tamanho)
    for y in tabela:
        print("".join(y))
        '''tabela[(len(tabela)+1)/2] = "X"
        posicao_do_x = len(tabela)/2
        posicao_do_x2 = int(posicao_do_x) // int(y)
        posicao_do_x3 = int(posicao_do_x) % int(y)
        tabela[int(posicao_do_x2)][int(posicao_do_x3)] = "X"'''
    print("@")
else:
    break
  • 1

    Is there any way to draw an example of what the exit would look like? It’s a little hard to understand exactly what a "right spiral starting in the middle".

  • 1

    Would be similar to that?

  • You want to make a Ulam spiral?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.