-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo10.py
67 lines (53 loc) · 1.64 KB
/
demo10.py
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
60
61
62
63
64
# -*- coding: utf8 -*-
import datetime
class Person(object):
def __init__(self, n, id):
self.name = n
self.id_card = id
def __repr__(self):
return '%s, %s' % (self.name, self.id_card)
@property
def birth_date(self):
return self.id_card[6:14]
@property
def sex(self):
y = int(self.id_card[16])
# 偶数是女,奇数是男
if y % 2 == 0:
return '女'
else:
return '男'
@property
def age(self):
#从身份证中取年份
z = int(self.id_card[6:10])
#获取今年的年份
d = datetime.datetime.today().year
return d - z
class Student(Person):
def __init__(self, n, id, school):
self.school = school
super(Student, self).__init__(n, id)
def is_student(self):
if self.age <= 19:
return True
else:
return False
class Teacher(Person):
def __init__(self, n, id, school, level):
self.school = school
self.level = level
super(Teacher, self).__init__(n, id)
if __name__ == '__main__':
x1 = Student('胡俊华', '360103199909150025', '上高二中')
if x1.is_student():
print ('''
姓名: %s 出生日期: %s 性别: %s 年龄: %s 学校: %s
''' % (x1.name, x1.birth_date, x1.sex, x1.age, x1.school))
else:
if x1.sex == '女':
print('she is not a student')
else:
print('he is not a student')
x2 = Teacher('胡志刚', '360102197209163874', '上高二中', '中级')
print '%s, 年龄: %s, 教师级别: %s' % (x2.name, x2.age, x2.level)