File: class/Extras/Code/people/person.py

class Person:
    def __init__(self, name, job=None, pay=0):
        self.name = name
        self.job  = job
        self.pay  = pay
    def lastName(self):
        return self.name.split()[-1]
    def giveRaise(self, percent):
        self.pay *= (1.0 + percent)
    def __str__(self):
        return '<Person: %s, %s>' % (self.name, self.pay)

class Manager(Person):
    def __init__(self, name, pay):
        Person.__init__(self, name, 'mgr', pay)
    def giveRaise(self, percent, bonus=.10):
        Person.giveRaise(self, percent + bonus)
    
if __name__ == '__main__':
    bob = Person('bob smith')
    sue = Person('sue jones', job='dev', pay=50000)
    tom = Manager('tom smith', 40000)
    print bob.name, ':', bob.lastName()
    print sue
    print tom    
    sue.giveRaise(.10)
    tom.giveRaise(.10)
    print sue
    print tom



[Home page] Books Code Blog Python Author Train Find ©M.Lutz