继承与派生作业

作业一:定义如下类,并最大程度地重用代码(继承,派生:子类重用父类方法,组合,)
    老师类
    学生类
    分数类
    课程类
    日期类

 

__author__ = 'luchuangao'

class People:
    def __init__(self,name,age,sex):
        self.name=name
        self.age=age
        self.sex=sex

class Teacher(People):
    def __init__(self,name,age,sex,alias,course):
        People.__init__(self,name,age,sex)
        self.alias=alias
        self.course=course

class Student(People):
    def __init__(self,name,age,sex,ID,grade):
        People.__init__(self,name,age,sex)
        self.id=ID
        self.grade=grade

class Grade:
    def __init__(self,linux,python):
        self.linux=linux
        self.python=python

class Course:
    def __init__(self,course_name,course_price,course_date,date):
        self.course_name=course_name
        self.course_price=course_price
        self.course_date=course_date
        self.date=date

class date:
    def __init__(self,year,month,day):
        self.year=year
        self.month=month
        self.day=day

d1=date('2017','4','19')
c1=Course('python全栈','15800','7m',d1)
t1=Teacher('luchuan',18,'male','导演',c1)
print(t1.name,t1.age,t1.sex,t1.alias)
print(t1.course.course_name,t1.course.course_price,t1.course.course_date)
print(c1.date.year,c1.date.month,c1.date.day,c1.course_date,c1.course_name,c1.course_price)

  

 

posted @ 2017-04-19 17:32  luchuangao  阅读(177)  评论(0编辑  收藏  举报