面向对象作业
作业_定义学校老师课程班级学生类.py
#面向对象编程作业,定义学校老师课程班级学生类 #定义几个类,尽可能定义多的数据属性及函数属性 class School: def __init__(self,name,addr,type): self.name = name self.addr = addr self.type = type def shang_ke(self): print('[%s]学校正在上课'%self.name) def zhao_sheng(self): print('[%s]学校在[%s]招生'%(self.name,self.addr)) s1 = School('北京大学','北京','公立大学') s1.shang_ke() s1.zhao_sheng() class Teacher: def __init__(self,name,course,level): self.name = name self.course = course self.level = level def shang_ke(self): print('[%s]老师是一个[%s]老师,他的级别是[%s],正在上课' %(self.name,self.course,self.level)) t1 = Teacher('月明','物理','教授') t1.shang_ke() class Course: def __init__(self,name,type): self.name = name self.type = type def course(self): print('这是[%s]课程,是[%s]课程' %(self.name,self.type)) c1 = Course('物理','必修') c1.course() class Class: def __init__(self,name,type): self.name = name self.type = type def class_info(self): print('班级名称是[%s],是[%s]'%(self.name,self.type)) c2 = Class('全栈开发3','Python') c2.class_info() class Student: def __init__(self,name,age,gender): self.name = name self.age = age self.gendet = gender def student_info(self): print('这个学生姓名是[%s]年龄[%d]性别[%s]'%(self.name,self.age,self.gendet)) s1 = Student('月明',18,'male') s1.student_info()