bank.py
class Account:
CHECKING = 0
SAVINGS = 1
def __init__(self, acct_num, cust_id, type=CHECKING, balance=0.0):
self.acct_num = acct_num
self.cust_id = cust_id
self.type = type
self.balance = balance
def __str__(self):
rep = "Acct:\t\t" + self.acct_num
rep += "\nCust ID:\t" + self.cust_id
rep += "\nType:\t\t"
if self.type == Account.CHECKING:
rep += "Checking"
else:
rep += "Savings"
rep += "\nBalance:\t$%.2f" % self.balance
return rep
def getBalance(self):
return self.balance
def getType(self):
return self.type
def deposit(self, amount):
if amount < 0:
print "Amount must be a positive amount"
else:
self.balance += amount
def withdrawal(self, amount):
if amount < 0:
print "Amount must be a positive amount"
else:
self.balance -= amount
def testAccount():
acct = Account("Sprenkle", "c0001", Account.CHECKING, 100.00)
print acct
acct.deposit(35)
acct.deposit(45)
acct.withdrawal(74.24)
acct.withdrawal(14.23)
print
print acct
testAccount()
Generated by GNU enscript 1.6.4.