Guest User

Untitled

a guest
Feb 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class BalanceError(Exception):
  2. value = "Sorry you only have $%6.2f in your account"
  3.  
  4. class BankAccount:
  5. def __init__(self, initialAmount):
  6. self.balance = initialAmount
  7. print "Account created with balance %5.2f" % self.balance
  8.  
  9. def deposit(self, amount):
  10. self.balance = self.balance + amount
  11.  
  12. def withdraw(self, amount):
  13. if self.balance >= amount:
  14. self.balance = self.balance - amount
  15. else:
  16. raise BalanceError, BalanceError.value % self.balance
  17.  
  18. def checkBalance(self):
  19. return self.balance
  20.  
  21. def transfer(self, amount, account):
  22. try:
  23. self.withdraw(amount)
  24. account.deposit(amount)
  25. except BalanceError:
  26. print BalanceError.value
Add Comment
Please, Sign In to add comment