I am supposed to write a class named Employee that holds the data of name, salary, and years of service. It calculates the monthly pension payout the employee will receive in retirement and display the three instance variables of the Employee objects. It also calls the Employee object’s pension method to calculate the monthly pension payout of this employee and also display it.
I do not get any output after running my program and that is the specific problem.
I am supposed to get something like this as the output:
Name: Joe Chen
Salary: 80000
Years of service: 30
Monthly pension payout: 3600.0
Process finished with exit code 0
Here is the full 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()
You're just printing an empty line. Change your functions to the 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
The \ in python is line continuation. Better yet put all of it on the same line like so:
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 the demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With