Chapter 1 : Overview

Example 1.1 Page No : 17

In [1]:
 

class BankAccount:
    def __init__(self,openingBalance): # constructor
        self.balance = openingBalance

    def deposit(self,amount): # makes deposit
        self.balance = self.balance + amount; 
    
    def withdraw(self,amount): # makes withdrawal
        self.balance = self.balance - amount; 

    def display(self):
        # displays balance 
        print 'balance=' , self.balance

# end class BankAccount

ba1 = BankAccount(100.00) # create acct
print 'Before transactions, ',
ba1.display()
# display balance
ba1.deposit(74.35)
ba1.withdraw(20.00)
print 'After transactions, ' ,
ba1.display()
Before transactions,  balance= 100.0
After transactions,  balance= 154.35
In [ ]: