Python Console Application: Payroll Evaluation - 1 Week
Python Console Application: Payroll Evaluation - 1 Week
Introduction
In this exercise, we will create a simple Python application that performs some calculations and involves simple conditional statements. For some reason (or to make things a little simpler), we will use Microsoft Visual Studio, which is freely available, but if you want, you can use any tool you judge necessary. In fact, you can create the following application directly on the console or terminal.
Practical Learning: Creating the Application
print("Payroll Evaluation") print("==================================================") print("Enter the following pieces of information") print("--------------------------------------------------") print("Employee Information") firstName = input("First Name: ") lastName = input("Last Name: ") hSalary = float(input("Hourly Salary: ")) print("==================================================") print("Time worked") print("--------------------------------------------------") monday = float(input("Monday: ")) tuesday = float(input("Tuesday: ")) wednesday = float(input("Wednesday: ")) thursday = float(input("Thursday: ")) friday = float(input("Friday: ")) timeWorked = monday + tuesday + wednesday + thursday + friday regTime = timeWorked overTime = 0.00 regPay = hSalary * timeWorked overPay = 0.00 if timeWorked > 40.00: regTime = 40.00 overTime = timeWorked - 40.00 regPay = hSalary * 40.00 overPay = hSalary * 1.50 * overTime netPay = regPay + overPay print("==================================================") print("Payroll Evaluation") print("==================================================") print("Employee Information") print("--------------------------------------------------") print(f"Full Name: {firstName} {lastName}") print(f"Hourly Salary: {hSalary:5.2f}") print("==================================================") print("Time Worked Summary") print('--------+---------+-----------+----------+--------') print(" Monday | Tuesday | Wednesday | Thursday | Friday") print('--------+---------+-----------+----------+--------') print(f"{monday:6.2f} |{tuesday:6.2f} |{wednesday:7.2f} |{thursday:7.2f} |{friday:6.2f}") print("========+=========+===========+==========+========") print("\t\t\t\tPay Summary") print("--------------------------------------------------") print("\t\t\t\tTime Pay") print("--------------------------------------------------") print(f"\t\tRegular:\t{regTime:4.2f}\t{regPay:8.2f}") print("--------------------------------------------------") print(f"\t\tOver Time:\t{overTime:5.2f}\t{overPay:8.2f}") print(f"-------------------------------------------------") print(f"\t\tNet Pay:\t{netPay:16.2f}") print("==================================================")
Payroll Evaluation ================================================== Enter the following pieces of information -------------------------------------------------- Employee Information First Name: Michael Last Name: Carlock Hourly Salary: 28.46 ================================================== Time worked -------------------------------------------------- Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 7.5 ================================================== Payroll Evaluation ================================================== Employee Information -------------------------------------------------- Full Name: Michael Carlock Hourly Salary: 28.46 ================================================== Time Worked Summary --------+---------+-----------+----------+-------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+-------- 7.00 | 8.00 | 6.50 | 8.50 | 7.50 ========+=========+===========+==========+======== Pay Summary -------------------------------------------------- Time Pay -------------------------------------------------- Regular: 37.50 1067.25 -------------------------------------------------- Over Time: 0.00 0.00 ------------------------------------------------- Net Pay: 1067.25 ================================================== Press any key to continue . . .
Payroll Evaluation ================================================== Enter the following pieces of information -------------------------------------------------- Employee Information First Name: Catherine Last Name: Busbey Hourly Salary: 24.37 ================================================== Time worked -------------------------------------------------- Monday: 9.5 Tuesday: 8 Wednesday: 10.5 Thursday: 9 Friday: 10.5 ================================================== Payroll Evaluation ================================================== Employee Information -------------------------------------------------- Full Name: Catherine Busbey Hourly Salary: 24.37 ================================================== Time Worked Summary --------+---------+-----------+----------+-------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+-------- 9.50 | 8.00 | 10.50 | 9.00 | 10.50 ========+=========+===========+==========+======== Pay Summary -------------------------------------------------- Time Pay -------------------------------------------------- Regular: 40.00 974.80 -------------------------------------------------- Over Time: 7.50 274.16 ------------------------------------------------- Net Pay: 1248.96 ================================================== Press any key to continue . . .
Using an Opposite Conditional Statement
In the previous code, we used the Greater Than (>) operator. As it happens, its opposite if the Less Than Or Equal (<=) operator. We are going to test it.
Practical Learning: Using a Different Conditional Statement
print("Payroll Evaluation") print("==================================================") print("Enter the following pieces of information") print("--------------------------------------------------") print("Employee Information") firstName = input("First Name: ") lastName = input("Last Name: ") hSalary = float(input("Hourly Salary: ")) print("==================================================") print("Time worked") print("--------------------------------------------------") monday = float(input("Monday: ")) tuesday = float(input("Tuesday: ")) wednesday = float(input("Wednesday: ")) thursday = float(input("Thursday: ")) friday = float(input("Friday: ")) timeWorked = monday + tuesday + wednesday + thursday + friday regTime = 40.00 overTime = timeWorked - 40.00 regPay = hSalary * 40.00 overPay = hSalary * 1.50 * overTime if timeWorked <= 40.00: regTime = timeWorked overTime = 0.00 regPay = hSalary * timeWorked overPay = 0.00 netPay = regPay + overPay print("==================================================") print("Payroll Evaluation") print("==================================================") print("Employee Information") print("--------------------------------------------------") print(f"Full Name: {firstName} {lastName}") print(f"Hourly Salary: {hSalary:5.2f}") print("==================================================") print("Time Worked Summary") print('--------+---------+-----------+----------+--------') print(" Monday | Tuesday | Wednesday | Thursday | Friday") print('--------+---------+-----------+----------+--------') print(f"{monday:6.2f} |{tuesday:6.2f} |{wednesday:7.2f} |{thursday:7.2f} |{friday:6.2f}") print("========+=========+===========+==========+========") print("\t\t\t\tPay Summary") print("--------------------------------------------------") print("\t\t\t\tTime Pay") print("--------------------------------------------------") print(f"\t\tRegular:\t{regTime:4.2f}\t{regPay:8.2f}") print("--------------------------------------------------") print(f"\t\tOver Time:\t{overTime:5.2f}\t{overPay:8.2f}") print(f"-------------------------------------------------") print(f"\t\tNet Pay:\t{netPay:16.2f}") print("==================================================")
Payroll Evaluation ================================================== Enter the following pieces of information -------------------------------------------------- Employee Information First Name: Herbert Last Name: Mann Hourly Salary: 32.17 ================================================== Time worked -------------------------------------------------- Monday: 7.5 Tuesday: 8. Wednesday: 8.5 Thursday: 6.5 Friday: 7 ================================================== Payroll Evaluation ================================================== Employee Information -------------------------------------------------- Full Name: Herbert Mann Hourly Salary: 32.17 ================================================== Time Worked Summary --------+---------+-----------+----------+-------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+-------- 7.50 | 8.00 | 8.50 | 6.50 | 7.00 ========+=========+===========+==========+======== Pay Summary -------------------------------------------------- Time Pay -------------------------------------------------- Regular: 37.50 1206.38 -------------------------------------------------- Over Time: 0.00 0.00 ------------------------------------------------- Net Pay: 1206.38 ================================================== Press any key to continue . . .
Payroll Evaluation ================================================== Enter the following pieces of information -------------------------------------------------- Employee Information First Name: Jeanine Last Name: Hewsen Hourly Salary: 34.05 ================================================== Time worked -------------------------------------------------- Monday: 9 Tuesday: 8.5 Wednesday: 10.5 Thursday: 9.5 Friday: 10 ================================================== Payroll Evaluation ================================================== Employee Information -------------------------------------------------- Full Name: Jeanine Hewsen Hourly Salary: 34.05 ================================================== Time Worked Summary --------+---------+-----------+----------+-------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+-------- 9.00 | 8.50 | 10.50 | 9.50 | 10.00 ========+=========+===========+==========+======== Pay Summary -------------------------------------------------- Time Pay -------------------------------------------------- Regular: 40.00 1362.00 -------------------------------------------------- Over Time: 7.50 383.06 ------------------------------------------------- Net Pay: 1745.06 ================================================== Press any key to continue . . .
|
|||
Home | Copyright © 2021-2025, FunctionX | Thursday 12 December 2024, 14:11 | Home |
|