Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. class BankAccount:
  2. def __init__(self, aId, pin, balance = 100): # balance's default value is 100
  3. self._id = aId
  4. self._pin = pin
  5. self._balance = balance
  6. @property
  7. def id(self):
  8. return self._id
  9. @property
  10. def pin(self):
  11. return self._pin
  12. @property
  13. def balance(self):
  14. return self._balance
  15.  
  16. @pin.setter
  17. def pin(self, newPin):
  18. self._pin = newPin
  19.  
  20. @balance.setter
  21. def balance(self, newBal):
  22. self._balance = newBal
  23.  
  24. def changePin(self, oldPin, newPin):
  25. if oldPin == self._pin:
  26. self._pin = newPin
  27. return True
  28. else:
  29. return False
  30.  
  31. def deposit(self, amount):
  32. if amount > 0: # Simple validation
  33. self._balance += amount
  34. return True
  35. else:
  36. return False
  37.  
  38. def withdraw(self, amount):
  39. if amount > 0 and amount <= self._balance:
  40. self._balance -= amount
  41. return True
  42. else:
  43. return False
  44.  
  45. def transfer(self, amount, tAccount): # tAccount is the account to transfer
  46. if amount > 0 and amount <= self._balance:
  47. self._balance -= amount
  48. tAccount._balance += amount # Add amount to the other account
  49. return True
  50. else:
  51. return False
  52.  
  53. def __str__(self):
  54. s = "Account: {} Balance: {:.2f}".format(self._id, self._balance)
  55. return s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement