Question: In Python: Classes allow us to define entirely new types. We might think of each type in Python as a set of values, and we
In Python:
Classes allow us to define entirely new types. We might think of each type in Python as a set of values, and we use a class declaration to describe how to build and interact with all the values of this brand new type. We will often need at minimum a constructor (telling us what instance variables to always create), __str__ method (telling Python how to represent the thing as a string), and then any extra methods that we deem useful ways of interacting with the new values.




Task 1 Course A course represents a specific course record as those appeared on your transcript. 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". 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 ou 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. numberar other. number and self.credit other credit and self.credit other credit m m 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
