मराठी

Define a class employee in Python with the given specifications: Instance variables: Employee number, name Methods: Getdata()- To input employee number and name Printdata()-

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Inheritance - EXERCISE [पृष्ठ ८४]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×