-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path25_Classes_e_listas.py
More file actions
69 lines (51 loc) · 1.35 KB
/
25_Classes_e_listas.py
File metadata and controls
69 lines (51 loc) · 1.35 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Carro:
marca = ""
ano = 0
preco :int
def __init__(self, marca, ano, preco):
self.marca = marca
self.ano = ano
self.preco = preco
def __str__(self):
return self.marca + " , " + str(self.ano) + " , " + str(self.preco)
def __repr__(self):
return "(" + str(self) + ")"
class Pessoa:
nome = ""
idade = 0
def __init__(self, nome, idade):
self.nome = nome
self.idade = idade
def __str__(self):
return self.nome + " , " + str(self.idade)
def __repr__(self):
return "(" + str(self) + ")"
def main():
a = Pessoa("Carlos", 21)
b = Pessoa("Filipa", 30)
c = Pessoa("matias", 22)
d = Pessoa("joao", 43)
e = Pessoa("ana", 25)
f = Pessoa("paulo", 60)
lista = []
lista.append(a)
lista.append(b)
lista.append(c)
lista.append(d)
lista.append(e)
lista.append(f)
lista.append(Carro("ford", 1990, 1000))
lista.append(Carro("nissa", 1990, 1000))
lista.append(Carro("citroen", 1990, 1000))
lista.append(Carro("Mustang", 1990, 1000))
print(lista)
print(len(lista))
for zz in lista:
if isinstance(zz, Pessoa) == True:
print(zz)
print(lista)
for k in lista:
if isinstance(k, Carro) == True:
print(k)
if __name__ == '__main__':
main()