English

Define a class trainer in Python with the given specifications: Instance variables: → Name  → T_ID  Methods  → getName()To print instance variable Name 2   getTID()To print instance variable T_ID

Advertisements
Advertisements

Question

Define a class trainer in Python with the given specifications:

Instance variables:

→ Name 
→ T_ID 
Methods 
→ getName()To print instance variable Name

2   getTID()To print instance variable T_ID
Define a class learner in Python with the given specifications:
Instance variables:
→ L_Name 
→ L_ID 
Methods
→ getName()To print instance variable L_Name 
→ getLID()To print instance variable L_ID 
Define a class Institute in Python with the given specifications:
Instance variables:
→ I_Name 
→ I_Code 
Methods
→ getName()To print instance variable I_Name 
→ getICode()To print instance variable I_Code 
The class Institute inherits the class Trainer and Learner

Code Writing
Definition
Advertisements

Solution

class Trainer(object):
    def __init__(self, name, t_id):
        self.name = name
        self.t_id = t_id

    def getName(self):
        print("Trainer name:", self.name)

    def getTID(self):
        print("Trainer ID:", self.t_id)

class Learner(object):
    def __init__(self, l_name, l_id):
        self.l_name = l_name
        self.l_id = l_id

    def getName(self):
        print("Learner name:", self.l_name)

    def getLID(self):
        print("Learner ID:", self.l_id)

class Institute(Trainer, Learner):
    def __init__(self, name, t_id, l_name, l_id, i_name, i_code):
        Trainer.__init__(self, name, t_id)
        Learner.__init__(self, l_name, l_id)
        self.i_name = i_name
        self.i_code = i_code

    def getICode(self):
        print("Institute code:", self.i_code)

    def getInstituteName(self):
        print("Institute name:", self.i_name)
shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Inheritance - EXERCISE [Page 82]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 4 Inheritance
EXERCISE | Q 18. | Page 82
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×