fork download
  1. def gerar(nLins, nCols, min, max):
  2. from random import randint
  3. vals = [None] * nLins
  4. for i in range(nLins):
  5. vals[i] = [0] * nCols
  6. for j in range(nCols):
  7. vals[i][j] = randint(min, max)
  8. return vals
  9.  
  10.  
  11. def mostrar(vals, linMin, linMax, colMin, colMax):
  12. for i in range(linMin, linMax):
  13. for j in range(colMin, colMax):
  14. print(vals[i][j], end=" ")
  15. print()
  16. print()
  17. return None
  18.  
  19.  
  20. def organizar(matriz):
  21. matriz_organizada = matriz.copy()
  22. matriz_organizada.sort(key=sum)
  23. return matriz_organizada
  24.  
  25.  
  26. qtd = '56'
  27. qtdLinhas = int(qtd[0])
  28. qtdColunas = int(qtd[1])
  29.  
  30. valores = gerar(qtdLinhas, qtdColunas, 10, 99)
  31. valores_organizados = organizar(valores)
  32.  
  33. print("Matriz gerada:")
  34. mostrar(valores, 0, qtdLinhas, 0, qtdColunas)
  35. print("Matriz organizada:")
  36. mostrar(valores_organizados, 0, qtdLinhas, 0, qtdColunas)
Success #stdin #stdout 0.02s 11696KB
stdin
Standard input is empty
stdout
Matriz gerada:
66 23 46 88 33 75 
59 36 20 68 93 63 
24 85 56 72 74 12 
53 24 51 84 92 13 
98 18 29 23 72 83 

Matriz organizada:
53 24 51 84 92 13 
24 85 56 72 74 12 
98 18 29 23 72 83 
66 23 46 88 33 75 
59 36 20 68 93 63