provinha 11: gabarito

provinha 11: gabarito

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):                     def g(x, y):                     def h(x, y, z):                                                                        
    for i in range(2):               x = [[0, 0, 0], [0, 0, 0]]       z[0][0] = x[0][0]*y[0][0] + x[0][1]*y[1][0] 
        for j in range(3):           for i in range(2):               z[0][1] = x[0][0]*y[0][1] + x[0][1]*y[1][1] 
            x[i][j] = y[i][j]+1          for j in range(3):           z[1][0] = x[1][0]*y[0][0] + x[1][1]*y[1][0] 
            y[i][j] = 4                      x[i][j] = y[i][j]+1      z[1][1] = x[1][0]*y[0][1] + x[1][1]*y[1][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]: [[4, 4, 4], [4, 4, 4]]

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

In [5]: y = x

In [6]: f(x, y)

In [7]: x

Out[7]: [[4, 4, 4], [4, 4, 4]]

In [8]: y

Out[8]: [[4, 4, 4], [4, 4, 4]]

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]: [[3, 3, 3], [3, 3, 3]]

In [13]: y

Out[13]: [[4, 4, 4], [4, 4, 4]]

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 , 0], [-1, 2]]

In [22]: y = [[2, 1], [ 1, 1]]

In [23]: z = [[0, 0], [ 0, 0]]

In [24]: h(x, y, z)

In [25]: z

Out[25]: [[2, 1], [0, 1]]

In [26]: x = [[1 , 0], [-1, 2]]

In [27]: y = [[2, 1], [ 1, 1]]

In [28]: h(x, y, x)

In [29]: x

Out[29]: [[2, 2], [0, 2]]

right


Comentários?