面向对象之继承与派生(学生管理系统)
##
class People:
def __init__(self,name,age,weight):
self.Name = name
self.Age = age
self.Weight = weight
def achievement(self):
"""业绩"""
return
def work(self):
"""生活方式"""
return
class Teacher(People):
"""老师"""
def __init__(self,name,age,weight,concat):
People.__init__(self,name,age,weight)
self.concat = concat
def achievement(self,walk):
"""讲课幽默"""
walk.talk = self.concat
return walk
def work(self,course,score):
"""批改作业"""
self.score = score
print("%s 开始批改 %s 作业" %(self.Name,course))
return (course,score)
class Student(People):
def __init__(self,name,age,weight,course):
People.__init__(self,name,age,weight)
self.course = course
def work(self,course):
"""提交作业"""
return ("%s 已经提交 %s 作业"%(self.Name,course))
class Course:
def __init__(self,course_name,course_startdate,course_price,teacher):
self.course_name = course_name
self.course_startdate = course_startdate
self.course_price = course_price
self.teacher = teacher
teach1_obj = Teacher('egon',39,136,18110221308)
couse1_obj = Course('python','2017-01-03',15800,teach1_obj)
stu1 = Student('piter',22,80,couse1_obj)
foinfo = {"Name":stu1.Name,"Age":stu1.Age,"course_name":stu1.course.course_name,\
"Name":couse1_obj.teacher.Name,"course_price":stu1.course.course_price,\
"course_startdate":stu1.course.course_startdate}
print ("学生名字\t年龄\t课程\t\t老师\t\t价格\t\t上课时间")
getinfo = """{Name}\t\t{Age}\t\t{course_name}\t\t{Name}\t\t{course_price}\t\t{course_startdate}
""".format_map(foinfo)
# print(stu1.Name,stu1.Age,stu1.course.course_name,
# stu1.course.course_price,stu1.
# course.course_startdate)
print(getinfo.strip('\n'))
print(stu1.work(stu1.course.course_name))
scoreinfo = teach1_obj.work(couse1_obj.course_name,90)
print("学生名字\t课程\t\t得分")
getscorelist = """{Name}\t\t{course_name}\t\t{score}""".format_map({
"Name":stu1.Name,"course_name":stu1.course.course_name,"score":scoreinfo[1]
}).strip('\n')
print(getscorelist)
运行结果:
学生名字 年龄 课程 老师 价格 上课时间
egon 22 python egon 15800 2017-01-03
piter 已经提交 python 作业
egon 开始批改 python 作业
学生名字 课程 得分
piter python 90