cours_progra/q1/renforcement/renforcement_2510/ex1.py
2023-02-15 13:40:50 +01:00

40 lines
856 B
Python

def ChangeInMatrix(tab, n, m):
"""Prend tab et le repartie sur n rangee et m colones
:tab: liste des eleves
:n: row
:m: culumn
:returns: matrix nxm with tab
"""
ret = list()
for i in range(n):
ret.append(list())
for j in range(m):
ret[i].append(0)
for i in range(len(tab)):
ret[i // n][i % m] = tab[i]
return ret
def printMatrix(matrix: list):
"""TODO: print a matrix in console
:matrix: matrix en entrée
"""
max_char = 0
for i in matrix:
for j in i:
if len(str(j)) > max_char:
max_char = len(str(j))
for i in matrix:
for j in i:
print(f'{j} {" " * (max_char - len(str(j)))}', end='')
print('')
if __name__ == "__main__":
printMatrix(ChangeInMatrix(list(range(1, 45)), 21, 14))