Advertisements
Advertisements
प्रश्न
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 payroll, which is derived from employee
Instance variable
Salary
Methods:
Inputdata() - To call Getdata() and input salary.
Outdata() - To call printdata() and to display salary.
Define another class leave, which is derived from payroll.
Instance variable
No of days
Methods:
acceptdata() - To call Inputdata() and input no of days.
showdata() - To call Outdata() and to display no of days.
Implement the above program in python.
कोड लेखन
परिभाषा
Advertisements
उत्तर
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 Payroll(Employee):
def inputdata(self):
self.getdata()
self.salary = float(input("Enter salary: "))
def outdata(self):
self.printdata()
print("Salary:", self.salary)
class Leave(Payroll):
def acceptdata(self):
self.inputdata()
self.no_of_days = int(input("Enter number of leave days: "))
def showdata(self):
self.outdata()
print("Number of leave days:", self.no_of_days)
obj = Leave()
obj.acceptdata()
obj.showdata()shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
