File: class/Extras/Other/PriorClasses/nasa-ksc-aug15/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, pct):
        self.pay *= (1.0 + pct)
    def __str__(self):
        return '[Person: %s, %.2f]' % (self.name, self.pay)

class Manager(Person):
    def giveRaise(self, pct, bonus=.10):
        Person.giveRaise(self, pct + bonus)       

if __name__ == '__main__':
    bob = Person('Bob Smith')
    sue = Person('Sue Jones', job='dev', pay=100000)
    print(bob)
    print(sue)
    print(bob.lastName(), sue.lastName())
    sue.giveRaise(.10)
    print(sue)
    tom = Manager('Tom Jones', 'mgr', 50000)
    print(tom)
    for obj in [bob, sue, tom]:
       obj.giveRaise(.10)
       print(obj)






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