-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.py
executable file
·62 lines (46 loc) · 1.48 KB
/
objects.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
#!/usr/bin/env python
class Person:
def __init__(self, name, ident):
self.name = name
self.ident = ident
class Course:
def __init__(self, title, info):
self.title = title
self.info = info
class Student(Person):
def __init__(self, name, id, lCourses):
Person.__init__(self, name, id)
self.lCourses = lCourses
self.dCourse2Info = {}
self.dCourse2Grade = {}
self.homework = None
def learn(self, aCourse):
self.dCourse2Info[aCourse] = aCourse.info
def setGrade(self, aCourse, grade):
self.dCourse2Grade[aCourse] = grade
class Teacher(Person):
def __init__(self, name, id, aCourse):
Person.__init__(self, name, id)
self.course = aCourse
def teach(self, lStudents):
for student in lStudents:
student.learn(self.course)
def grade(self, lStudents):
for student in lStudents:
grade = listen(student)
student.setGrade(self.aCourse, grade)
def listen(self, aStudent):
grade = calcGrade(aStudent.homework)
return grade
math = Course("Math", "knowledge about math ...")
stats = Course("Statistics", "stats know-how")
john = Student("John", 12, [math, stats])
mary = Student("Mary", 34, [stats,])
allStudents = [john, mary]
stats_prof = Teacher("Brad", 56, stats)
math_prof = Teacher("Ellen", 78, math)
allTeachers = [stats_prof, math_prof]
allPeople = allStudents + allTeachers
for p in allPeople:
print(p.name, p.ident)
stats_prof.teach(allStudents)