File: class/Extras/Other/PriorClasses/oracle-aug12/person.py

class Person:
    """
    stuff about people
    """
    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):
        "percent should be 0..1"
        self.pay *= (1.0 + percent)
    def __str__(self):
        return '[Peron: %s, %s, %s]' % (self.name, self.pay, self.job)

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)
    print bob
    print sue
    print bob.lastName(), sue.lastName()
    sue.giveRaise(.10)
    print sue
    tim = Manager('Tim Jones', 40000)
    tim.giveRaise(.10)
    print tim
    
        



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