This question refers to the number problem 1557, of the site Uri Online Judge of the category Beginners.
See here the entirety of the statement.
As it is possible to notice the first paragraph of the statement says: Write an algorithm that reads an integer N (0 N 15), corresponding to the order of an integer matrix M, and construct the matrix according to the example below.
The example - the question refers to - is formed by matrize quadrada
, where each line is formed by increasing geometric rate progressions 2
, as shown in the above example.
To solve this question we can use the following algorithm:
n = 9999
while True:
n = int(input())
if n == 0:
break
m = list()
# Matriz base com elemento "0"
for i in range(n):
m.append([])
for j in range(n):
m[i].append(0)
# Inserindo os elementos pedidos
m[0][0] = 1
for i in range(0, n):
if i >= 1:
m[i][0] = m[i - 1][0] * 2
for j in range(1, n):
m[i][j] = m[i][j - 1] * 2
# Exibindo a matriz formada
T = len(str(m[n - 1][n - 1]))
for i in range(n):
for j in range(n):
m[i][j] = str(m[i][j])
while len(m[i][j]) < T:
m[i][j] = ' ' + m[i][j]
M = ' '.join(m[i])
print(M)
print()
Note that the primeiro aninhamento
block for
will be responsible for creating a base matrix with elements "0"
.
Already the segundo aninhamento
block for
will be responsible for assembling the matrix with the appropriate values.
The terceiro aninhamento
block for
is responsible for displaying the matrix in tabular form.
This code has already been tested, submitted and properly approved on the website Uri.
Please correct code indentation.
– Woss
Please enter the full description of the problem.
– Pablo Almeida
@Masterzub Start by checking if the indentation in the question code matches the one that came from your file, and if not, adjust the indentation here in the question so it looks exactly the same as the one you have. Remember that in Python indentation is vital, and without knowing how you have yours is difficult to help
– Isac
@Pabloalmeida, this is the description of the problem: https://www.urionlinejudge.com.br/judge/pt/problems/view/1557
– MasterZub