Create a class Emp with 3 instance variables named: emp_id, emp_name and pay. In this, emp_id and emp_name are the strings and pay data type is a float. This class also has a member function ‘total_salary()’ – this method will compute the total salary of employees.
The total salary should be sum of all allowances using:
Sample Input:
Enter the employee id:1
Enter the employee name: Bob
Enter the pay:2000
Sample Output:
Employee Id: 1 , Employee Name: Bob, Total Salary:2260.00
class Emp:
#initialize the attributes
def __init__(self, name, id, pay):
self.__name = name
self.__id = id
self.__pay = pay
#set the attributes
def set_name(self, name):
self.__name = name
def set_id(self, id):
self.__id = id
def set_pay(self, pay):
self.__pay = pay
#return the attributes
def get_name(self):
return self.__name
def get_id(self):
return self.__id
def get_department(self):
return self.__department
#return the objects state as a string
def total_salary(self):
Total_salary = self.__pay + (0.1*self.__pay) + (0.05*self.__pay) + (0.08*self.__pay)-(0.1*self.__pay)
return Total_salary
Comments
Leave a comment