#学校
class School: def __init__(self, name, address, type): self.name = name self.address = address self.type = type def take_exam(self): #学校函数属性:考试 print('%s正在举行考试'%self.name) def take_vacation(self): print('%s的%s将要放假'%(self.address, self.name)) p1 = School("河南工业大学", "高新区莲花街", "public") print(p1.__dict__) p1.take_exam() p1.take_vacation()
#老师
class Teacher: def __init__(self, name, gender, age): self.name = name self.gender = gender self.age = age def teaching(self): print('%s老师正在教学'%self.name) def assign_homework(self): print('这个%s岁的%s老师%s正在给学生布置作业'%(self.age, self.gender, self.name)) p2 = Teacher("刘文杰", "女", "24") p2.teaching() p2.assign_homework()
#课程
class Curriculum: def __init__(self, data, grade): self.grade = grade self.data = data def add_cur(self): print('%s%s的课程增加了'%(self.data, self.grade)) def over_cur(self): print('%s%s的课程结束了,谢谢大家四年来的配合!'%(self.data,self.grade)) p3 = Curriculum('16级', '化学三班') p3.add_cur() p3.over_cur()
#班级
class Class: def __init__(self, address, name): self.address= address self.name = name def take_activity(self): print('%s%s的同学正在举办团日活动'%(self.address,self.name )) def dine_together(self): print('%s%s的同学正在聚餐'%(self.address, self.name)) p4 = Class("工大", "化学三班") p4.take_activity() p4.dine_together()
#学生
class Student: def __init__(self,name, gender, class_gra): self.name = name self.gender = gender self.class_gra = class_gra def game(self, game): print('%s同学正在玩%s'%(self.name, game)) def study(self): print("%s的%s同学正在学习"%(self.class_gra, self.name)) p5 = Student('蒲金灵', 'girl', '化学四班') p6 = Student('刘文豪', 'male', '化学三班') p5.study() p6.game('王者荣耀')