How To Create A Python Pay Program

Photo by Pontus Wellgraf on Unsplash

How to create a python program that calculates pay and overtime

This is a Python 3 tutorial for creating a pay and overtime program, and in order to get started I always start with a comment about what the program that I am building is. By using the # key, you can then create comments in Python.

# program that calculates overtime
# get users to input their hours of work and if over 40 get the overtime rate for the extra time

After the comment, I would usually import the functions I would utilize within the program. In this program, I did not use a function, so I did not have to import anything for this program.


Next, I will get input from the user to input into the computer how many hours they have worked as well as what their rate of pay is in order to calculate how much they would get paid normally with 40 hours and overtime if they worked more than 40 hours. This program also calculates a tax rate from the gross pay when is then the net pay, and in this case,  we have set our tax rate at 8 percent.

hours = input('Input hours to calculate your net pay: ')
rate = input('Input rate of pay to calculate your net pay: ') 
taxrate = (int(hours) * int(rate)) * .08

After I have gotten the user to input their hours and rate next, we will use if/else statements. Or if/else statements are important for our program to function correctly, and our statements are as follows:

if int(hours) <= 40:
              print((int(hours) * int(rate)) - taxrate)

elif int(hours) > 40:

              print( ((int(hours) - 40) * (int(rate) * 1.5)) + (40 * int(rate)) - taxrate)

No comments:

Post a Comment

Great Ways To Learn How To Start Coding

Good Places To Get Help When Learning How To Code There are many places to learn how to do many things not only code, and today in this a...