Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BankAccount:
- def __init__(self, aId, pin, balance = 100): # balance's default value is 100
- self._id = aId
- self._pin = pin
- self._balance = balance
- @property
- def id(self):
- return self._id
- @property
- def pin(self):
- return self._pin
- @property
- def balance(self):
- return self._balance
- @pin.setter
- def pin(self, newPin):
- self._pin = newPin
- @balance.setter
- def balance(self, newBal):
- self._balance = newBal
- def changePin(self, oldPin, newPin):
- if oldPin == self._pin:
- self._pin = newPin
- return True
- else:
- return False
- def deposit(self, amount):
- if amount > 0: # Simple validation
- self._balance += amount
- return True
- else:
- return False
- def withdraw(self, amount):
- if amount > 0 and amount <= self._balance:
- self._balance -= amount
- return True
- else:
- return False
- def transfer(self, amount, tAccount): # tAccount is the account to transfer
- if amount > 0 and amount <= self._balance:
- self._balance -= amount
- tAccount._balance += amount # Add amount to the other account
- return True
- else:
- return False
- def __str__(self):
- s = "Account: {} Balance: {:.2f}".format(self._id, self._balance)
- return s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement