-
Notifications
You must be signed in to change notification settings - Fork 57
/
Final Exam - Problem 5.py
72 lines (56 loc) · 2.2 KB
/
Final Exam - Problem 5.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
class edx(object):
def __init__(self, courses):
self.myCourses = []
for course in courses:
self.myCourses.append(courseInfo(course))
def setGrade(self, grade, course="6.01x"):
"""
grade: integer greater than or equal to 0 and less than or equal to 100
course: string
This method sets the grade in the courseInfo object named by `course`.
If `course` was not part of the initialization, then no grade is set, and no
error is thrown.
The method does not return a value.
"""
# fill in code to set the grade
for c in self.myCourses:
if c.courseName == course:
c.setGrade( grade)
def getGrade(self, course="6.02x"):
"""
course: string
This method gets the grade in the the courseInfo object named by `course`.
returns: the integer grade for `course`.
If `course` was not part of the initialization, returns -1.
"""
# fill in code to get the grade
for c in self.myCourses:
if c.courseName == course:
return c.getGrade()
return -1
def setPset(self, pset, score, course="6.00x"):
"""
pset: a string or a number
score: an integer between 0 and 100
course: string
The `score` of the specified `pset` is set for the
given `course` using the courseInfo object.
If `course` is not part of the initialization, then no pset score is set,
and no error is thrown.
"""
for i in range(len(self.myCourses)):
if self.myCourses[i].courseName == course:
self.myCourses[i].setPset( pset, score)
def getPset(self, pset, course="6.00x"):
"""
pset: a string or a number
score: an integer between 0 and 100
course: string
returns: The score of the specified `pset` of the given
`course` using the courseInfo object.
If `course` was not part of the initialization, returns -1.
"""
for c in self.myCourses:
if c.courseName == course:
return c.getPset(pset)
return -1