-
Notifications
You must be signed in to change notification settings - Fork 1
/
lecture12-3-code.py
60 lines (44 loc) · 1.3 KB
/
lecture12-3-code.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
import datetime
class Person(object):
def __init__(self, name):
self.name = name
self.birthday = None
self.lastName = name.split(' ')[-1]
def setBirthday(self, month, day, year):
self.birthday = datetime.date(year, month, day)
def getAge(self):
if self.birthday == None:
raise ValueError
return (datetime.date.today() - self.birthday).days
def getLastName(self):
return self.lastName
def __lt__(self, other):
if self.lastName == other.lastName:
return self.name < other.name
return self.lastName < other.lastName
def __str__(self):
return self.name
class MITPerson(Person):
nextIdNum = 0
def __init__(self, name):
Person.__init__(self, name)
self.idNum = MITPerson.nextIdNum
MITPerson.nextIdNum += 1
def getIdNum(self):
return self.idNum
def __lt__(self, other):
return self.idNum < other.idNum
class Student(MITPerson):
pass
class UG(Student):
def __init__(self, name, classYear):
MITPerson.__init__(self, name)
self.year = classYear
def getClass(self):
return self.year
class Grad(Student):
pass
class TransferStudent(Student):
pass
def isStudent(obj):
return isinstance(obj, Student)