Created
September 18, 2008 16:46
-
-
Save trek/11444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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