File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class Pessoa :
2- def __init__ (self , nome = None , idade = 41 ):
2+ def __init__ (self , * filhos , nome = None , idade = 41 ):
33 self .nome = nome
44 self .idade = idade
5+ self .filhos = list (filhos )
56
67 def cumprimentar (self ):
78 return f"Ola { id (self )} "
89
910 def __repr__ (self ):
10- return f"{ self .nome } tem { self .idade } anos"
11+ txtSaida = f"Meu nome é { self .nome } e tenho { self .idade } anos"
12+
13+ if self .filhos :
14+ txtSaida = txtSaida + f"\n Tenho { len (self .filhos )} filhos:"
15+ for filho in self .filhos :
16+ txtSaida = txtSaida + f"\n ==> { filho } "
17+
18+ return txtSaida
19+
20+
1121
1222
1323if __name__ == '__main__' :
14- p1 = Pessoa ( 'Xico' )
15- p2 = Pessoa ( 'Arthur' , 7 )
16- print ( Pessoa . cumprimentar ( p1 ) )
17- print ( p1 . cumprimentar ())
18- print ( id ( p1 ))
19-
20- print ( p1 )
21- print (p2 )
24+ filhos = [( 'Arthur' , 7 ), ( 'Alice' , 0 )]
25+
26+ pai = Pessoa ( nome = 'Adao Oliveira' , idade = 41 )
27+
28+ for filho in filhos :
29+ pai . filhos . append ( Pessoa ( nome = filho [ 0 ], idade = filho [ 1 ]))
30+
31+ print (pai )
You can’t perform that action at this time.
0 commit comments