-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinherit.py
More file actions
59 lines (46 loc) · 1.46 KB
/
inherit.py
File metadata and controls
59 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class SchoolMember(object):
'''学习成员基类'''
member=0
def __init__(self,name,age,sex):
self.name=name
self.age=age
self.sex=sex
self.enroll()
def enroll(self):
'注册'
print('just enrolled a new school member {}.'.format(self.name))
SchoolMember.member+=1
def tell(self):
print('---{}---'.format(self.name))
for k,v in self.__dict__.items():
print(k,v)
print('----end----')
def delete(self):
print('开除了{}'.format(self.name))
SchoolMember.member-=1
class Teacher(SchoolMember):
'教师'
def __init__(self,name,age,sex,salary,course):
SchoolMember.__init__(self,name,age,sex)
self.salary=salary
self.course=course
def teaching(self):
print('Teacher {} is teaching {}'.format(self.name,self.course))
class Student(SchoolMember):
'学生'
def __init__(self,name,age,sex,course,tuition):
SchoolMember.__init__(self,name,age,sex)
self.course=course
self.tuition=tuition
self.amount=0
def pay_tuition(self,amount):
print('student {} has just paied {}'.format(self.name,self.amount))
self.amount+=amount
t1=Teacher('Wusir',28,'M','3000','python')
t1.tell()
s1 = Student('haitao', 38, 'M', 'python', 30000)
s1.tell()
s2 = Student('lichuang', 12, 'M', 'python', 11000)
print(SchoolMember.member)
s2.delete()
print(SchoolMember.member)