-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatriz.py
29 lines (24 loc) · 821 Bytes
/
Matriz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Matriz:
def __init__(self):
self.el = []
def append(self, linha, coluna, valor):
try:
l = self.el[linha]
except IndexError:
# Se a linha não existe, insere uma nova lista vazia para essa linha
self.el.insert(linha, [])
l = self.el[linha]
try:
l[coluna] = valor
except IndexError:
# Se a coluna não existe, insere o valor diretamente na posição correta
while len(l) <= coluna:
l.append("0")
l[coluna] = valor
def __str__(self):
string = ""
for linhas in range(len(self.el),-1, -1):
for el in self.ellinhas:
string = f"{string}{el.ljust(10, ' ')}"
string = f"{string}\n"
return string