Getting output after running python program

I have to write a class named Employee that contains data about name, salary and years of service. It calculates the monthly retirement benefit that the employee will receive in retirement and displays three variable instance of Employee objects. He also calls the Employee's Retirement Object Method to calculate the monthly payment of that employee's pensions and also display it.

I am not getting any results after running my program and this is a particular problem.

I should get something like this as output:

Name: Joe Chen
Salary: 80000
Years of service: 30
Monthly pension payout: 3600.0

Process finished with exit code 0

      

Here is the complete code.

class Employee:


    # init method implementation
    def __init__(self, EmpName, EmpSalary, EmpYos):
        self.EmpName = EmpName
        self.EmpSalary = EmpSalary
        self.EmpYos = EmpYos

    def displayEmployeeDetails(self):
        print "\nName ", self.EmpName,

    # defines the salary details
    def displaySalary(self):
        print "\nSalary", self.EmpSalary

    # defines the years of service
    def displayYoservice(self):
        print "\nYears of Service", self.EmpYos

    # defines pension
    def MonthlypensionPayout(self):
        print "\nMonthly Pension Payout:", self.EmpSalary * self.EmpYos * 0.0015


def main():


    # creates instance for employee 1
    Emplo1 = Employee("Joe Chen", 80000, 30)
    # creates instance for employee 2
    Emplo2 = Employee("Jean park", 60000, 25)

    # Function calls
    Emplo1.displayEmployeeDetails()
    Emplo1.displaySalary()
    Emplo1.displayYoservice()
    Emplo1.MonthlypensionPayout()
    # function calls
    Emplo2.displayEmployeeDetails()
    Emplo2.displaySalary()
    Emplo2.displayYoservice()
    Emplo2.MonthlypensionPayout()

main()

      

+3


source to share


1 answer


You are just printing a blank line. Change your functions below:

def displayEmployeeDetails(self):

  print \
  "\nName ", self.EmpName

# defines the salary details
def displaySalary(self):


 print \
 "\nSalary", self.EmpSalary

# defines the years of service
def displayYoservice(self):


 print \
 "\nYears of Service", self.EmpYos

      

\

in python - line continuation. Better yet, put it all on one line:



def displayEmployeeDetails(self):

  print "\nName ", self.EmpName

# defines the salary details
def displaySalary(self):


 print "\nSalary", self.EmpSalary

# defines the years of service
def displayYoservice(self):


 print "\nYears of Service", self.EmpYos

      

See demo .

+5


source







All Articles