Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the python code below: A) What is the superclass of Course? B) How many in

ID: 3874453 • Letter: G

Question

Given the python code below:  

A) What is the superclass of Course?

B) How many instances of Course are created?

C) The first invocation of an inherited method by a Course object is an invocation of the method named?

D) There is a usual python naming convention to indicate a class attribute is to be treated as a private attribute. If we apply this convention to the name of the first instance variable (also called an instance data member) of the class Course, the name of that variable should be changed to?

class Course (list) """An example for reviewing classes in python""" csMajorCour ses = [] otherCour ses = [] def init (self, cname, isCore) self. cours ename = cname self.isCore-isCore self.prerequisites [] if( isCore self.csMajorCourses.append (self) else: self.otherCourses.append (self)] def prereuisite (self, preCourse) self.prerequisites.append (preCourse) return self.prerequisites def str (self): return self.coursename mycourseCourse ("COMP2005", True) mycourse.prerequisite( Course ("COMP2001", True)) for c in ("COMP2006", "COMP2007", "COMP2008") : Course (c, True) mycourse.extend ( ("Bob", "Harriet", "Jonas", "Ahmed", "Franklin") ) print (mycourse.pop )) print (mycourse)

Explanation / Answer

A) object is the superclass of Course because all classes inherit from object in Python.

B) Only one instance is created which is called mycourse.

C) This is kind of a tricky question. Technically speaking the very first invocation would be the init() method which is nothing but the constructor call. If the call to constructor is not considered, then the first invocated method would be prerequisite(). But my bet would be on init().

D) In Python, private variables are represented by adding underscore in the beginning of it. So the first variable in class Course should be renamed as _csMajorCourses.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote