Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #LAB10B bankaccount.py
- class BankAccount (object) :
- # class constructor
- def __init__(self, acct, num, bal, credit = 2500) :
- self.Holder = acct
- self.Number = num
- self.Balance = bal
- self.LineOfCredit = credit
- # member functions
- def balance(self) :
- return self.Balance
- def deposit(self, amount) :
- self.Balance = amount
- def transfer(self, target, amount) :
- if (self.Balance - amount < -self.LineOfCredit) :
- # insufficient funds
- return False
- else :
- self.Balance -= amount
- target.Balance += amount
- return True
- def withdraw(self, amount) :
- if (self.Balance - amount < -self.LineOfCredit) :
- # insufficient funds
- return False
- else :
- self.Balance -= amount
- return True
- # instantiate a class object
- acctInfoCustomer1 = BankAccount("King", 27427, 19231.10)
- # verify the account balance
- # display account information
- acctInfoCustomer2 = BankAccount("Hasan", 27428, 1953100.10)
- # verify the account balance
- acctInfoCustomer2.transfer(acctInfoCustomer1, 5999)
- acctInfoCustomer2.withdraw(2000)
- bal1 = acctInfoCustomer1.balance()
- bal2 = acctInfoCustomer2.balance()
- print (acctInfoCustomer1.Holder)
- print (acctInfoCustomer1.Number)
- print ("\nBalance: $%.2f" % bal1)
- print ("\n")
- # display account information
- print (acctInfoCustomer2.Holder)
- print (acctInfoCustomer2.Number)
- print ("\nBalance: $%.2f" % bal2)
- print ("\n")
- #19231.0
- #19532100.10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement