Skip to content

Instantly share code, notes, and snippets.

@trek
Created September 18, 2008 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trek/11444 to your computer and use it in GitHub Desktop.
Save trek/11444 to your computer and use it in GitHub Desktop.
class BalanceError(Exception):
value = "Sorry you only have $%6.2f in your account"
class BankAccount:
def __init__(self, initialAmount):
self.balance = initialAmount
print "Account created with balance %5.2f" % self.balance
def deposit(self, amount):
self.balance = self.balance + amount
def withdraw(self, amount):
if self.balance >= amount:
self.balance = self.balance - amount
else:
raise BalanceError, BalanceError.value % self.balance
def checkBalance(self):
return self.balance
def transfer(self, amount, account):
try:
self.withdraw(amount)
account.deposit(amount)
except BalanceError:
print BalanceError.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment