本帖最后由 suchocolate 于 2020-12-9 12:56 编辑 class BankAccount:
def __init__(self):
self.balance = 0
def save(self, money):
self.balance += money
def withdrawal(self, money):
self.balance -= money
class MinBalancedBankAccount(BankAccount):
def __init__(self):
super().__init__()
self.minimum_balance = 100
def withdrawal(self, money):
tp = self.balance - money
if tp < self.minimum_balance:
print('Sorry, A minimum of 100 must be maintained.')
else:
self.balance = tp
return True
class TransferMinBalancedBankAccount(MinBalancedBankAccount):
def __init__(self):
super().__init__()
def transfer(self, transfer_to_account, amount):
if self.withdrawal(amount):
transfer_to_account.balance += amount
if __name__ == '__main__':
a = TransferMinBalancedBankAccount()
b = TransferMinBalancedBankAccount()
a.save(300)
b.save(400)
b.transfer(a, 100)
print(a.balance)
print(b.balance)
b.transfer(a, 201)
print(a.balance)
print(b.balance)
|