Second Summer 2006


Lecture Notes Seventeen: Designing Classes.
We have spent a great deal of time discussing and developing this:
class Account(object):
    def __init__(self, initial):
        self.balance = initial
    def report(self):
        return self.balance
    def buy(self, price):
        self.balance += price

kohls = Account(10) # purchased $10 worth of mechandise
print "Kohl's balance (due) now: ", kohls.report()
kohls.buy(20) # purchase $20 worth of merchandise more
print "Kohl's balance (due) now: ", kohls.report()
target = Account(34.25) # open acount with Target
print "Target balance (due) now: ", target.report()
target.buy(-34.25) # pay Target bill off
print "Target balance (due) now: ", target.report()
kohls.buy(-40) # pay and put some money in the Kohl's account too
print "Kohl's balance (due) now: ", kohls.report()


Last updated: July 18, 2006 by Adrian German for A201/A597