मराठी

Implement the following using multilevel information. → Create a student class with student number and name → Class graduate is created by using student. → Graduate class is created using subject

Advertisements
Advertisements

प्रश्न

Implement the following using multilevel information.

→ Create a student class with student number and name

→ Class graduate is created by using student.

→ Graduate class is created using subject code and subject name.

→ Class Post Graduate is created by using Graduat

→ Post Graduate class is created using master subject code and master subject name

कोड लेखन
Advertisements

उत्तर

class Student(object):
    def __init__(self, student_no, name):
        self.student_no = student_no
        self.name = name

    def show_student(self):
        print("Student number:", self.student_no)
        print("Name:", self.name)

class Graduate(Student):
    def __init__(self, student_no, name, subject_code, subject_name):
        super().__init__(student_no, name)
        self.subject_code = subject_code
        self.subject_name = subject_name

    def show_graduate(self):
        self.show_student()
        print("Graduate subject code:", self.subject_code)
        print("Graduate subject name:", self.subject_name)

class PostGraduate(Graduate):
    def __init__(self, student_no, name, subject_code, subject_name,
                 master_subject_code, master_subject_name):
        super().__init__(student_no, name, subject_code, subject_name)
        self.master_subject_code = master_subject_code
        self.master_subject_name = master_subject_name

    def show_postgraduate(self):
        self.show_graduate()
        print("Master subject code:", self.master_subject_code)
        print("Master subject name:", self.master_subject_name)

p = PostGraduate(101, "Anu", "CS101", "Computer Science",
                 "MCS201", "Artificial Intelligence")
p.show_postgraduate()

Inheritance chain: Student → Graduate → PostGraduate
Type: Multilevel inheritance.

shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Inheritance - EXERCISE [पृष्ठ ८६]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 4 Inheritance
EXERCISE | Q 25. | पृष्ठ ८६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×