-1
I’m making a small game, however, I need to call this function 3 times, in the first call of the function it performs as expected, however, in the second and third call it does not do what I expect. That is, from the second call it does not modify the matrix ( it takes the original matrix and not the modified matrix after the first call ) which is what I need because that’s why I created the function. function does not modify the matrix outside the function? I can not put the matrix inside the function, pq it would be executed 3 times.
import random
import time
Tamanho = 21
Matriz = [[0]* 7 for i in range(3)]
Lista_De_Numeros = [Numero + 1 for Numero in range(Tamanho)]
for i in range(3):
for j in range(7):
Numero = random.choice(Lista_De_Numeros)
Matriz[i][j] = Numero
Lista_De_Numeros.remove(Numero)
def Escolha (M):
Linha_Do_Numero = int(input("Qual a linha que seu número ficou ? "))
if Linha_Do_Numero == 1:
M = [(M[1]), (M[0]), (M[2])]
print(M)
M = [[(M[0][6]), (M[0][3]), (M[0][0]), (M[1][4]), (M[1][1]), (M[2][5]),(M[2][2]) ], [(M[0][5]), (M[0][2]), (M[1][6]), (M[1][3]), (M[1][0]), (M[2][4]), (M[2][1])], [(M[0][4]), (M[0][1]), (M[1][5]), (M[1][2]), (M[2][6]), (M[2][3]), (M[2][0])]]
print(M)
elif Linha_Do_Numero == 2:
M= [(M[0]), (M[1]), (M[2])]
print (M)
M = [[(M[2][6]), (M[2][3]), (M[2][0]), (M[1][4]), (M[1][1]), (M[0][5]),(M[0][2]) ], [(M[2][5]), (M[2][2]), (M[1][6]), (M[1][3]), (M[1][0]), (M[0][4]), (M[0][1])], [(M[2][4]), (M[2][1]), (M[1][5]), (M[1][2]), (M[0][6]), (M[0][3]), (M[0][0])]]
print (M)
elif Linha_Do_Numero == 3:
M= [(M[0]), (M[2]), (M[1])]
print (M)
M = [[(M[2][6]), (M[2][3]), (M[2][0]), (M[1][4]), (M[1][1]), (M[0][5]),(M[0][2]) ], [(M[2][5]), (M[2][2]), (M[1][6]), (M[1][3]), (M[1][0]), (M[0][4]), (M[0][1])], [(M[2][4]), (M[2][1]), (M[1][5]), (M[1][2]), (M[0][6]), (M[0][3]), (M[0][0])]]
print (M)
print()
print(" Escolha um único número abaixo")
print()
print(' linha 1',' linha 2',' linha 3')
print()
print (Matriz[0],' ',Matriz[1],' ',Matriz[2])
print()
Escolha(Matriz)
print()
Escolha(Matriz)
print()
Escolha(Matriz)
print()
print(Matriz[1][3])
I didn’t understand, it was a bit superficial the explanation, anyway thank you
– Dumb
now it was well explained, but even with the Returns my function continues to do the same thing!
– Dumb