Practical 7: To Calculate Salary of an Employee Given His Basic Pay (Take as Input from User). Calculate Gross Salary of Employee. Let HRA be 10% of Basic Pay and TA be 5% of Basic Pay. Let Employee Pay Professional Tax as 2% of Total Salary. Calculate Net Salary Payable After Deductions.
Problem Statement:
Write a Python program to calculate the salary of an employee. The program should take the basic pay as input from the user and calculate:
- HRA (House Rent Allowance): 10% of basic pay
- TA (Travel Allowance): 5% of basic pay
- Professional Tax: 2% of the total salary (basic pay + HRA + TA)
- Gross Salary: Basic pay + HRA + TA
- Net Salary: Gross salary – Professional Tax
The program should then display the net salary payable to the employee after deductions.
Solution Code:
# Program to calculate salary of an employee
# Input basic pay from the user
basic_pay = float(input("Enter the basic pay of the employee: "))
# Calculate HRA (House Rent Allowance) which is 10% of basic pay
hra = 0.10 * basic_pay
# Calculate TA (Travel Allowance) which is 5% of basic pay
ta = 0.05 * basic_pay
# Calculate Gross Salary
gross_salary = basic_pay + hra + ta
# Calculate Professional Tax which is 2% of the gross salary
professional_tax = 0.02 * gross_salary
# Calculate Net Salary
net_salary = gross_salary - professional_tax
# Display the calculated salary components
print(f"Basic Pay: {basic_pay}")
print(f"HRA: {hra}")
print(f"TA: {ta}")
print(f"Gross Salary: {gross_salary}")
print(f"Professional Tax: {professional_tax}")
print(f"Net Salary Payable: {net_salary}")
Output:
- The program will prompt the user to input the employee’s basic pay.
- The program will then calculate and display the following:
- HRA (House Rent Allowance): 10% of basic pay
- TA (Travel Allowance): 5% of basic pay
- Gross Salary: Basic pay + HRA + TA
- Professional Tax: 2% of Gross Salary
- Net Salary: Gross salary – Professional Tax
Enter the basic pay of the employee: 25000
Basic Pay: 25000.0
HRA: 2500.0
TA: 1250.0
Gross Salary: 28750.0
Professional Tax: 575.0
Net Salary Payable: 28175.0
Process finished with exit code 0
Explanation:
Below is the explanation of F.E. PPS Unit 1 Practical 7 solution where we have written Python program to Calculate Salary of an Employee Given His Basic Pay.
- Input of Basic Pay:
- The program starts by asking the user to input the employee’s basic pay using the input() function. This input is converted to a float type to handle decimal values.
- HRA Calculation:
- The program calculates the House Rent Allowance (HRA) as 10% of the basic pay using the formula:
HRA=0.10×Basic PayHRA = 0.10 \times \text{Basic Pay}
- The program calculates the House Rent Allowance (HRA) as 10% of the basic pay using the formula:
- TA Calculation:
- The Travel Allowance (TA) is calculated as 5% of the basic pay using the formula:
TA=0.05×Basic PayTA = 0.05 \times \text{Basic Pay}
- The Travel Allowance (TA) is calculated as 5% of the basic pay using the formula:
- Gross Salary Calculation:
- The Gross Salary is the sum of the basic pay, HRA, and TA.
Gross Salary=Basic Pay+HRA+TA\text{Gross Salary} = \text{Basic Pay} + \text{HRA} + \text{TA}
- The Gross Salary is the sum of the basic pay, HRA, and TA.
- Professional Tax Calculation:
- The Professional Tax is 2% of the gross salary:
Professional Tax=0.02×Gross Salary\text{Professional Tax} = 0.02 \times \text{Gross Salary}
- The Professional Tax is 2% of the gross salary:
- Net Salary Calculation:
- The Net Salary is calculated by subtracting the professional tax from the gross salary:
Net Salary=Gross Salary−Professional Tax\text{Net Salary} = \text{Gross Salary} – \text{Professional Tax}
- The Net Salary is calculated by subtracting the professional tax from the gross salary:
- Displaying the Results:
- Finally, the program prints the calculated salary components: Basic Pay, HRA, TA, Gross Salary, Professional Tax, and the Net Salary Payable.
Key Concept Learned:
- Mathematical Calculations:
- The practical demonstrates how to apply percentage calculations to derive components of salary based on given rules (HRA, TA, Professional Tax).
- Handling User Input:
- The program shows how to handle user input for financial data and perform calculations based on that input, emphasizing real-world scenarios like salary computation.
- Arithmetic Operations:
- The program involves performing basic arithmetic operations such as multiplication, addition, and subtraction to calculate the salary components.
- Formatted Output:
- The program demonstrates how to display results in a readable format using Python’s print() function. This is especially useful when dealing with financial figures that need to be presented clearly to users.: