Advertisements
Advertisements
प्रश्न
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
कोड लेखन
व्याख्या
Advertisements
उत्तर
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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
