Pythondex
Python Programs

Python Payroll Calculator With Loop

Last updated June 19, 2023 by Jarvis Silva

In this tutorial we will create a python payroll calculator with loop, this payroll program first we will asks the user to enter hours worked, hour rate, pf and tax then it will calculate the basic salary and deduct pf and tax and finally it will print the total salary so now let’s see how to do this in code.

Python Code For Payroll Calculator Program


is_stop = False

while is_stop == False:

    hours_worked = int(input("How many hours worked: "))
    hour_rate = int(input("Rate per hour: "))
    
    pf = int(input("PF Amount: "))
    tax = int(input("Tax Payable: "))

    basic_salary = hours_worked * hour_rate
    total_salary = basic_salary - (pf + tax)

    print(f"After deductions your total salary is ${total_salary}")
    
    q = input("Do you want to calculate another payroll enter y or n: ")
    
    if(q == 'n'):
        is_stop = True

Above is the code for payroll calculator done using loops so let’s see how this code works in simple points:

  • The code sets the initial value of the variable is_stop to False.
  • It enters a while loop that will continue as long as the value of is_stop is False.
  • Inside the loop, the user is prompted to enter the number of hours worked and the rate per hour.
  • The user is then asked to input the PF (Provident Fund) amount and the tax payable.
  • The basic salary is calculated by multiplying the hours worked by the rate per hour.
  • The total salary is calculated by subtracting the PF and tax from the basic salary.
  • The calculated total salary is displayed to the user.
  • The user is asked whether they want to calculate another payroll by entering ‘y’ or ‘n’.
  • If the user enters ‘n’, indicating they don’t want to calculate another payroll, the variable is_stop is set to True, which will exit the while loop and end the program.

Now to run this program you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer or you can use this online python compiler.

After running this program you will asked to enter the hours worked, hour rate, pf and tax then it will print the total salary, Below is an example output. I have created this python payroll calculator using loop so it will run till enter n when it asks you do you want to continue.


How many hours worked: 40
Rate per hour: 22
PF Amount: 2
Tax Payable: 2
After deductions your total salary is $876
Do you want to calculate another payroll enter y or n: y
How many hours worked: 43
Rate per hour: 23
PF Amount: 23
Tax Payable: 23
After deductions your total salary is $943
Do you want to calculate another payroll enter y or n: n

I hope you found this tutorial helpful and useful, do share this tutorial with your friends who might be interested in this program.

Here are some more python drawing tutorials for you:

I hope you found what you were looking for from this tutorial, and if you want more python programs and tutorials like this, do join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂