From 82bb9431b75eb6f15b3e867b67307e26292ca9df Mon Sep 17 00:00:00 2001 From: cadica Date: Tue, 21 Jan 2020 09:42:37 -0300 Subject: [PATCH 1/7] criada a classe pessoa --- oo/__init__.py | 0 oo/pessoa.py | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 oo/__init__.py create mode 100644 oo/pessoa.py diff --git a/oo/__init__.py b/oo/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/oo/pessoa.py b/oo/pessoa.py new file mode 100644 index 000000000..e1da50e22 --- /dev/null +++ b/oo/pessoa.py @@ -0,0 +1,2 @@ +class Pessoa: + pass \ No newline at end of file From 18c3944123377941d8e1a9264827f4a6850db3a9 Mon Sep 17 00:00:00 2001 From: cadica Date: Tue, 21 Jan 2020 09:55:30 -0300 Subject: [PATCH 2/7] criado o metodo cumprimentar --- oo/pessoa.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index e1da50e22..a23fb3f9c 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,2 +1,9 @@ class Pessoa: - pass \ No newline at end of file + def cumprimentar(self): + return f'Ola {id(self)}' + +if __name__ == '__main__': + p = Pessoa() + print(Pessoa.cumprimentar(p)) + print(id(p)) + print(p.cumprimentar()) From 45f81a6edff8c5be6f45c8d7eada7b437d5358b1 Mon Sep 17 00:00:00 2001 From: cadica Date: Tue, 21 Jan 2020 11:52:02 -0300 Subject: [PATCH 3/7] =?UTF-8?q?criado=20atributos=20de=20inst=C3=A2ncia=20?= =?UTF-8?q?nome=20e=20idade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index a23fb3f9c..e836f3ea1 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,9 +1,17 @@ class Pessoa: + def __init__(self, nome=None, idade=50): + self.nome = nome + self.idade = idade + def cumprimentar(self): return f'Ola {id(self)}' if __name__ == '__main__': - p = Pessoa() + p = Pessoa('Ricardo') print(Pessoa.cumprimentar(p)) print(id(p)) print(p.cumprimentar()) + print(p.nome) + p.nome = 'Arruda' + print(p.nome) + print(p.idade) From 26c0192f528bc3025e47085d6fa381bb2be381bc Mon Sep 17 00:00:00 2001 From: cadica Date: Tue, 21 Jan 2020 12:50:22 -0300 Subject: [PATCH 4/7] criado atributo complexo filhos --- oo/pessoa.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index e836f3ea1..0fa76e9a3 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,5 +1,6 @@ class Pessoa: - def __init__(self, nome=None, idade=50): + def __init__(self, *filhos, nome=None, idade=70): + self.filhos = list(filhos) self.nome = nome self.idade = idade @@ -7,11 +8,12 @@ def cumprimentar(self): return f'Ola {id(self)}' if __name__ == '__main__': - p = Pessoa('Ricardo') - print(Pessoa.cumprimentar(p)) - print(id(p)) - print(p.cumprimentar()) - print(p.nome) - p.nome = 'Arruda' - print(p.nome) - print(p.idade) + ricardo = Pessoa(nome='Ricardo') + antonio = Pessoa(ricardo, nome='Antonio') + print(Pessoa.cumprimentar(antonio)) + print(id(antonio)) + print(antonio.cumprimentar()) + print(antonio.nome) + print(antonio.idade) + for filho in antonio.filhos: + print(filho.nome) From bd7ac0aea83c5ce0618c0529968c27185ecc4457 Mon Sep 17 00:00:00 2001 From: cadica Date: Tue, 21 Jan 2020 12:58:07 -0300 Subject: [PATCH 5/7] criado e removido objeto do tipo pessoa --- oo/pessoa.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oo/pessoa.py b/oo/pessoa.py index 0fa76e9a3..6ef48f1a1 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -17,3 +17,7 @@ def cumprimentar(self): print(antonio.idade) for filho in antonio.filhos: print(filho.nome) + antonio.sobrenome = 'Arruda' + del antonio.filhos + print(antonio.__dict__) + print(ricardo.__dict__) From b3af9aefd26c7f0c87d4203fb7d2ce056cfd0ad4 Mon Sep 17 00:00:00 2001 From: cadica Date: Tue, 21 Jan 2020 13:11:07 -0300 Subject: [PATCH 6/7] criado atributo de classe olhos --- oo/pessoa.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 6ef48f1a1..45000a7b4 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,4 +1,6 @@ class Pessoa: + olhos = 2 + def __init__(self, *filhos, nome=None, idade=70): self.filhos = list(filhos) self.nome = nome @@ -17,7 +19,14 @@ def cumprimentar(self): print(antonio.idade) for filho in antonio.filhos: print(filho.nome) - antonio.sobrenome = 'Arruda' del antonio.filhos + antonio.sobrenome = 'Arruda' + antonio.olhos = 4 + del antonio.olhos print(antonio.__dict__) print(ricardo.__dict__) + Pessoa.olhos = 3 + print(Pessoa.olhos) + print(antonio.olhos) + print(ricardo.olhos) + print(id(Pessoa.olhos), id(antonio.olhos), id(ricardo.olhos)) \ No newline at end of file From 6d85196049a644e659c834a1ef796257648bf1b0 Mon Sep 17 00:00:00 2001 From: cadica Date: Tue, 21 Jan 2020 16:10:54 -0300 Subject: [PATCH 7/7] =?UTF-8?q?implementado=20motor=20e=20dire=C3=A7ao?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/carro.py | 32 ++++++++++++++++++++++++++++++++ oo/pessoa.py | 12 +++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 oo/carro.py diff --git a/oo/carro.py b/oo/carro.py new file mode 100644 index 000000000..f7cc1c385 --- /dev/null +++ b/oo/carro.py @@ -0,0 +1,32 @@ +class carro: + pass + +NORTE = 'Norte' +LESTE = 'Leste' +SUL = 'Sul' +OESTE = 'Oeste' + +class direcao: + rotacao_a_direita_dct = {NORTE: LESTE, LESTE: SUL, SUL: OESTE, OESTE: NORTE} + rotacao_a_esquerda_dct = {NORTE: OESTE, OESTE: SUL, SUL: LESTE, LESTE: NORTE} + + def __init__(self): + self.valor = NORTE + + def girar_a_direita(self): + self.valor = self.rotacao_a_direita_dct[self.valor] + + def girar_a_esquerda(self): + self.valor = self.rotacao_a_esquerda_dct[self.valor] + +class motor: + def __init__(self): + self.velocidade = 0 + + def acelertar(self): + self.velocidade += 1 + + def frear(self): + self.velocidade -= 2 + self.velocidade = max(0, self.velocidade) + diff --git a/oo/pessoa.py b/oo/pessoa.py index 45000a7b4..5af25b90d 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -9,6 +9,14 @@ def __init__(self, *filhos, nome=None, idade=70): def cumprimentar(self): return f'Ola {id(self)}' + @staticmethod + def metodo_statico(): + return 42 + + @classmethod + def nome_e_atributos_de_classe(cls): + return f'{cls} - olhos {cls.olhos}' + if __name__ == '__main__': ricardo = Pessoa(nome='Ricardo') antonio = Pessoa(ricardo, nome='Antonio') @@ -29,4 +37,6 @@ def cumprimentar(self): print(Pessoa.olhos) print(antonio.olhos) print(ricardo.olhos) - print(id(Pessoa.olhos), id(antonio.olhos), id(ricardo.olhos)) \ No newline at end of file + print(id(Pessoa.olhos), id(antonio.olhos), id(ricardo.olhos)) + print(Pessoa.metodo_statico(), ricardo.metodo_statico(), antonio.metodo_statico()) + print(Pessoa.nome_e_atributos_de_classe(), antonio.nome_e_atributos_de_classe())