Created
September 22, 2025 21:09
-
-
Save luizomf/a26cd0400a6a756e17f6263f4ef20f4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Pessoa: | |
| def __init__(self, nome, idade, comendo=False, falando=False): | |
| self.nome = nome | |
| self.idade = idade | |
| self.comendo = comendo | |
| self.falando = falando | |
| def comer(self, alimento): | |
| if self.comendo: | |
| print(f"{self.nome} já está comendo.") | |
| return | |
| if self.falando: | |
| print(f"{self.nome} não pode comer enquanto está falando.") | |
| return | |
| print(f"{self.nome} está comendo {alimento}.") | |
| self.comendo = True | |
| def parar_comer(self): | |
| if not self.comendo: | |
| print(f"{self.nome} não está comendo.") | |
| return | |
| print(f"{self.nome} parou de comer.") | |
| self.comendo = False | |
| def falar(self, assunto): | |
| if self.falando: | |
| print(f"{self.nome} já está falando.") | |
| return | |
| if self.comendo: | |
| print(f"{self.nome} não pode falar enquanto está comendo.") | |
| return | |
| print(f"{self.nome} está falando sobre {assunto}.") | |
| self.falando = True | |
| def parar_falar(self): | |
| if not self.falando: | |
| print(f"{self.nome} não está falando.") | |
| return | |
| print(f"{self.nome} parou de falar.") | |
| self.falando = False | |
| if __name__ == "__main__": | |
| p1 = Pessoa("Luiz", 29) | |
| p2 = Pessoa("João", 40) | |
| p1.comer("Maçã") | |
| p1.falar("POO") | |
| p1.parar_comer() | |
| p1.falar("POO") | |
| p2.falar("Hardware") | |
| p2.comer("Pão") | |
| p2.parar_falar() | |
| p2.comer("Pão") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment