Advertisements
Advertisements
Question
Define a class employee in Python with the given specifications:
Instance variables:
Employee number, name
Methods:
Getdata()- To input employee number and name
Printdata()- To display employee number and name
Define another class Teaching, which is derived from employee
Instance variable
Department name
Methods:
Inputdata() - To call Getdata() and input department name.
Outdata() - To call printdata() and to display department name.
Define another class Non_teaching, which is derived from employee
Instance variable
Designation
Methods:
Inputdata() - To call Getdata() and input designation.
Outdata() - To call printdata() and to display designation.
Implement the above program in python.
Code Writing
Definition
Advertisements
Solution
class Employee(object):
def getdata(self):
self.emp_no = input("Enter employee number: ")
self.name = input("Enter employee name: ")
def printdata(self):
print("Employee number:", self.emp_no)
print("Name:", self.name)
class Teaching(Employee):
def inputdata(self):
self.getdata()
self.department = input("Enter department name: ")
def outdata(self):
self.printdata()
print("Department:", self.department)
class NonTeaching(Employee):
def inputdata(self):
self.getdata()
self.designation = input("Enter designation: ")
def outdata(self):
self.printdata()
print("Designation:", self.designation)
teacher = Teaching()
teacher.inputdata()
teacher.outdata()
staff = NonTeaching()
staff.inputdata()
staff.outdata()
shaalaa.com
Is there an error in this question or solution?
