Question: class Course: Define the Course class. ? def __init__(self, number, credit, grade): Course constructor. All three parameters must be stored to instance variables of the
class Course: Define the Course class. ? def __init__(self, number, credit, grade): Course constructor. All three parameters must be stored to instance variables of the same names (number, credit, and grade).
o number :: str. Represents course number, like "CS112" or "MATH113".
o credit :: int. Represents credit hours. You can assume it will always be a positive integer.
o grade :: str. Represents letter grade. Can only be 'A','B','C','D','F', or 'IP'. If the provided grade is not one of these (for example, grade == "K"), then raise a CourseError with the message "bad grade 'K'". (You can skip this exception-raising part until later).
def __str__(self): returns a human-centric string representation. If number=="CS112", credit==4, and grade=="A", then the returned string must be "CS112: credit 4, grade A" (note the four single spaces). ?
def __eq__(self,other): we want to check that two courses are equal (our self and this other course). We compare each instance variable like so (this is the definition!) return self.number==other.number and self.credit==other.credit and self.grade==other.grade ?
def is_passing(self): checks whether this course has passed or not according to grade. Return False if the grade is 'F' or 'IP'; return True otherwise.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
