-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge1-6.py
74 lines (60 loc) · 2.18 KB
/
challenge1-6.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
65
66
67
68
69
70
71
72
73
74
class Student:
"""A class to represent a University student"""
# Add code here ...
def __init__(self,firstname,lastname,course):
self.firstname = firstname
self.lastname = lastname
self.course = course
self.modulecode = []
def showDetails(self):
print(self.firstname,self.lastname,'on course:',self.course)
print('Enrolled on following modules:')
for i in self.modulecode:
print(i)
def changeCourse(self,newcourse):
for i in self.course:
i = newcourse
class Module:
"""A class to represent a single module"""
# Add code here ...
def __init__(self,name,code,tutor):
self.name = name
self.code = code
self.tutor = tutor
self.enrolled_students = []
def enrolStudent(self,student:Student):
fullname = student.firstname +' '+student.lastname
self.enrolled_students.append(fullname)
student.modulecode.append(self.code)
def showAllEnrolledStudents(self):
if len(self.enrolled_students):
print('Enrolled on module:',self.code)
for i in self.enrolled_students:
print(i)
else:
print('No students for',self.code,'yet')
def main():
# Create some students and some modules ...
s1 = Student('ken','barlow','english')
s2 = Student('mike','baldwin','business')
s3 = Student('harold','legg', 'medicine')
m1 = Module('English language and semantics', 'A101','Wanda Pickle')
m2 = Module('Engineering principles','E102','Buzz Jones')
m3 = Module('Anatomy','M105','Greg House')
# Now enrol some students on some modules ...
m1.enrolStudent(s1)
m1.enrolStudent(s2)
m2.enrolStudent(s1)
m2.enrolStudent(s3)
# Have a look at some students and some modules ...
s1.showDetails()
s2.showDetails()
s3.showDetails()
m1.showAllEnrolledStudents()
m2.showAllEnrolledStudents()
m3.showAllEnrolledStudents()
# Change a course ...
s1.changeCourse('engineering')
s1.showDetails()
if __name__ == "__main__":
main()