Employee Salary
Write Python script for the following:
Create a class Employee with three instance variables named: employee_id, employee_name and basic_pay. In this, employee id and name are string values and basic pay is a float value. This class is also contains a member function ‘calculate_net_salary()’ – this method should calculate and return the net salary of employees.
The net salary should be calculated using the formula: net salary=(basic pay+DA+TA+HRA)-PF
where:
DA is 10% of basic pay.
TA is 5% of basic pay.
HRA is 8% of basic pay.
PF is 10% of basic pay.
Get employee id, name and basic pay from the user and store those values into the variables; eid, ename and basic_pay respectively.
Create an object for the ‘Employee’ class by invoking a parameterized constructor with three arguments: employee id, name and basic pay. The object name should be ‘emp_obj’. Finally, display the id, name and net salary of the employee as shown in the sample output.
Refer the sample input and output statements for more clarifications.
Note:
Strictly follow the naming conventions for variable objects and functions as specified in the problem description.
Sample Input:
Enter the employee id: E101
Enter the name : Jane
Enter the basic pay : 20000
Sample Output :Employee Id: E101
Employee Name: Jane
Net Salary : 22600.00
Code :-
class Employee: def __init__(self,employee_id,employee_name,basic_pay): self.employee_id=employee_id self.employee_name=employee_name self.basic_pay=basic_pay def calculate_net_salary(self): da=self.basic_pay*10/100 ta=self.basic_pay*5/100 hra=self.basic_pay*8/100 pf=self.basic_pay*10/100 net_pay=(self.basic_pay+da+ta+hra)-pf return net_pay eid=input("Enter the employee id:") ename=input("Enter the employee name:") basic_pay=float(input("Enter the basic pay:")) emp_obj=Employee(eid,ename,basic_pay) print("\nEmployee Id:",emp_obj.employee_id) print("Employee Name:",emp_obj.employee_name) net_salary=emp_obj.calculate_net_salary() print("Net Salary :%.2f" %net_salary)