from abc import ABCMeta, abstractmethod
class Account(metaclass=ABCMeta):
def __init__(self, number, name, age):
self.number = number
self.name = name
self.age = age
self._balance = 0
def deposit(self, value):
self._balance += value
@abstractmethod
def month_pass(self):
pass
@property
def balance(self):
return self._balance
def __str__(self):
return f'Conta:{self.number:05d}-{self.name}, Saldo:{self.balance:.2f}'
def __eq__(self, other):
return self.number == other.number and isinstance(self, type(other))
class CurrentAccount(Account):
def month_pass(self):
self._balance -= 2
class SavingAccount(Account):
def month_pass(self):
self._balance *= 1.01
self._balance -= 3
account_luccas = (CurrentAccount(1,'Luccas',27), SavingAccount(1,'Luccas',27))
account_luccas[0].deposit(100)
account_luccas[1].deposit(100)
for account in account_luccas:
print(account)
account.month_pass()
print(account)
print(account_luccas[0] == account_luccas[1])