Python Pay Program

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 are able to 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 then import the functions that 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 there hours and rate next, we will then use if/else statements. Our 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

Best Devices To Get Started With Programming

Having a good solid computer is vital to start coding, and HP offers solid laptops for coders at every level.