Answer:
Here is the Python program:
class Course:
def __init__(self,number, title):
self.number = number
self.title = title
def print_info(self):
print("Course Information:")
print("Course Number:", self.number)
print("Course Title:", self.title)
class OfferedCourse(Course):
def __init__(self, number, title,instructor_name,term,class_time):
self.number = number
self.title = title
self.instructor_name = instructor_name
self.term = term
self.class_time=class_time
if __name__ == "__main__":
course_number = input()
course_title = input()
o_course_number = input()
o_course_title = input()
instructor_name = input()
term = input()
class_time = input()
my_course = Course(course_number, course_title)
my_course.print_info()
my_offered_course = OfferedCourse(o_course_number, o_course_title, instructor_name, term, class_time)
my_offered_course.print_info()
print('Instructor Name:', my_offered_course.instructor_name)
print('Term:', my_offered_course.term)
print('Class Time:', my_offered_course.class_time)
Explanation:
Course is a base class with attributes number and title. It has a print_info() method that displays the course number and title.
self keyword is the keyword which is used to easily access all the instances defined within a Course class, including its method and attributes number and title.
__init__ is a constructor which is called when an instance is created from the Course, and access is required to initialize the attributes number and title of Course class.
OfferedCourse is a class which is derived from base class Course. In addition to attributes number and title, it has attributes attributes instructor_name, term, and class_time.
A special attribute __name__. The value of __name__ attribute is set to “__main__” in order to run this module as a main program. In this main program input() method is used to take input from user. The input is the course number, title, instructor name, term and class time. The object my_course of Course class is created and the constructor of Course class is called passing the course_number and course_title using this object to access the attributes (member variables number and term) of the Course class. Next the instance my_course is used to call function print_info() of Course class.
The object my_offered_course of OfferedCourse class is created and the constructor of OfferedCourse class is called passing the o_course_number, o_course_title, instructor_name, term, class_time using this object to access the attributes number, title, instructor_name,term, class_time OfferedCourse class. Next the instance my_offered_course is used to call function print_info() of Course class. Here it is to be noticed that the derived class OfferedCourse uses the method print_info() of its base class Course. Last three print statements of the main program use object my_offered_course to access the attributes instructor_name, term and class_time of class OfferedCourse to display the their values.
The screenshot of the program output is attached.