provinha 12: solução

provinha 12: solução

por José Coelho de Pina -
Número de respostas: 0

Questão. Suponha que o Python tenha lido todas as funções a seguir (teclamos F5 no spyder).

    def f(x, y): 
        for i in range(2):
            for j in range(3):
                x[i][j] = 2
                y[i][j] = 3
                
    def g(x, y): 
        x = [[0, 0, 0], [0, 0, 0]]
        for i in range(2):
            for j in range(3):
                x[i][j] = y[i][j]+1
        return x        

        

A seguir está uma transcrição de uma seção do Python Shell. Complete as lacunas com o valor do resultado da expressão correspondente. Se ocorrer um erro, escreva apenas ERRO.

In [1]: x = [[1, 1, 1], [1, 1, 1]]

In [2]: f(x, x)

In [3]: x

Out[3]: [[3, 3, 3], [3, 3, 3]]

In [4]: x = [[1, 1, 1], [1, 1, 1]]

In [5]: y = x

In [6]: f(x, y)

In [7]: x

Out[7]: [[3, 3, 3], [3, 3, 3]]

In [8]: y

Out[8]: [[3, 3, 3], [3, 3, 3]]

In [9]: x = [[1, 1, 1], [1, 1, 1]]

In [10]: y = [[2, 2, 2], [2, 2, 2]]

In [11]: f(x, y)

In [12]: x

Out[12]: [[2, 2, 2], [2, 2, 2]]

In [13]: y

Out[13]: [[3, 3, 3], [3, 3, 3]]

In [14]: x = [[1, 1, 1], [1, 1, 1]]

In [15]: y = [[2, 2, 2], [2, 2, 2]]

In [16]: z = g(x,y)

In [17]: z[0][0] = 5

In [18]: x

Out[18]: [[1, 1, 1], [1, 1, 1]]

In [19]: y

Out[19]: [[2, 2, 2], [2, 2, 2]]

In [20]: z

Out[20]: [[5, 3, 3], [3, 3, 3]]

In [21]: x = [1] * 3

In [22]: y = x * 2

In [23]: x[1] = 2

In [24]: y

Out[24]: [1, 1, 1, 1, 1, 1]

In [25]: x = [1] * 3

In [26]: y = [x] * 2

In [27]: x[1] = 2

In [28]: y

Out[28]: [[1, 2, 1], [1, 2, 1]]

right


Comentários?