Question: I need help finishing this template I have code listed under the requirments Complete the following in Practice Labs: Create code that will open a
I need help finishing this template I have code listed under the requirments
Complete the following in Practice Labs:
Create code that will open a text file for storing the employee information. The file must be opened so that entered data is added to the data already in the file.
Modify the code that stores the data in list objects to now write the from date, to date, employee name, hours worked, pay rate, and income tax rate as a record in pipe-delimited format to the text file
After the user terminates the data entry loop, call a new function that will:
Get input from the user for the From Date for which the report should be run. If the user enters All then all records will be read and displayed. Validate that the from date entered is in the format mm/dd/yyyy.
Write a loop to read the records from the text file. If the user entered All or the from date in the record matches what the user entered, store each data element in a variable, and for that employee calculate the income tax and net pay.
Display the from date, to date, employee name, hours worked, hourly rate, gross pay, income tax rate, income taxes and net pay for the employee inside the loop.
Increment the total number of employees, total hours, total tax, total net pay and store the values in a dictionary object inside the loop.
Display the totals after the loop terminates.
Submit the Python source code file and a Word document that contains a screen shot of input and display for two employees, each with a different from date; a screen shot of the display of totals when the user enters All; a screen shot of the totals when the user enters a From Date. A minimum of five employees must be entered and at least two different start dates to receive full credit. Include a 1-2 sentence reflection on the successes and/or challenges you had with this assignment.
Ensure all functionality is working correctly and code is written efficiently. For purposes of this assignment, writing code efficiently is defined as:
Using correct naming conventions for all variables and objects.
Using correct naming conventions for functions and methods.
Using built-in functions whenever possible.
Using the fewest lines of code needed to return multiple values from functions.
Using the fewest lines of code needed to complete the functionality defined.
# # # write the line of code to import the datetime library (Hint: see Week 1 Lab 3 solution as a guide # write the line of code to assign Employees.txt to the variable FILENAME (Hint: see week 6, lab 2 as a guide) def GetEmpName(): empname = input("Enter employee name: ") return empname def GetDatesWorked(): while True: date_str = input("Enter from date (YYYY-MM-DD): ") try: fromdate = datetime.strptime(date_str, "%Y-%m-%d") except ValueError: print("Invalid date format. Try again.") print() continue # skip next if statement and re-start loop break while True: date_str = input("Enter to date (YYYY-MM-DD): ") try: todate = datetime.strptime(date_str, "%Y-%m-%d") except ValueError: print("Invalid date format. Try again.") print() if todate <= fromdate: print("To date must be after from date. Try again.") print() else: break return fromdate, todate def GetHoursWorked(): hours = float(input('Enter amount of hours worked: ')) return hours def GetHourlyRate(): hourlyrate = float(input ("Enter hourly rate: ")) return hourlyrate def GetTaxRate(): taxrate = float(input ("Enter tax rate: ")) return taxrate def CalcTaxAndNetPay(hours, hourlyrate, taxrate): grosspay = hours * hourlyrate incometax = grosspay * taxrate netpay = grosspay - incometax return grosspay, incometax, netpay def printinfo(DetailsPrinted): TotEmployees = 0 TotHours = 0.00 TotGrossPay = 0.00 TotTax = 0.00 TotNetPay = 0.00 #**************************************************************************************************************************** # write the line of code that will open the file in read mode and assign it to EmpFile (Hint: see week 6, lab 2 as a guide) while True: rundate = input ("Enter start date for report (MM/DD/YYYY) or All for all data in file: ") if (rundate.upper() == "ALL"): break try: rundate = datetime.strptime(rundate, "%Y-%m-%d") break except ValueError: print("Invalid date format. Try again.") print() continue # skip next if statement and re-start loop while True: EmpDetail = EmpFile.readline() # write the if statemment that will break out of the while loop when no data is left in the file # write the line of code that will remove the carriage return from EmpDetail # write the ine of code that will split EmpDetail on the pipe delimiter and assign to the list EmpList #******************************************************************************************************************************** fromdate = EmpList[0] if (str(rundate).upper() != "ALL"): checkdate = datetime.strptime(fromdate, "%Y-%m-%d") if (checkdate < rundate): continue todate = EmpList[1] empname = EmpList[2] hours = float(EmpList[3]) hourlyrate = float(EmpList[4]) taxrate = float(EmpList[5]) grosspay, incometax, netpay = CalcTaxAndNetPay(hours, hourlyrate, taxrate) print ("********************************************************") print("Name: ", empname) print("Hours Worked: ", f"{hours:,.2f}") print("Hourly Rate: ", f"{hourlyrate:,.2f}") print("Gross Pay : ",f"{grosspay:,.2f}") print("Tax Rate: ", f"{taxrate:,.1%}") print("Income Tax: ", f"{incometax:,.2f}") print("Net Pay: ", f"{netpay:,.2f}") print ("********************************************************") print() TotEmployees += 1 TotHours += hours TotGrossPay += grosspay TotTax += incometax TotNetPay += netpay EmpTotals["TotEmp"] = TotEmployees EmpTotals["TotHrs"] = TotHours EmpTotals["TotGrossPay"] = TotGrossPay EmpTotals["TotTax"] = TotTax EmpTotals["TotNetPay"] = TotNetPay DetailsPrinted = True if (DetailsPrinted): #skip of no detail lines printed PrintTotals (EmpTotals) else: print("No detail information to print") def PrintTotals(EmpTotals): print() print(f'Total Number Of Employees: {EmpTotals["TotEmp"]}') print(f'Total Hours Worked: {EmpTotals["TotHrs"]:,.2f}') print(f'Total Gross Pay: {EmpTotals["TotGrossPay"]:,.2f}') print(f'Total Income Tax: {EmpTotals["TotTax"]:,.2f}') print(f'Total Net Pay: {EmpTotals["TotNetPay"]:,.2f}') #*************************************************************************************************************************************** if __name__ == "__main__": # write the line of code that will open the file in append mode and assign it to EmpFile (Hint: see week 6, lab 2 as a guide) #EmpDetailList = [] EmpTotals = {} DetailsPrinted = False while True: empname = GetEmpName() if (empname.upper() == "END"): break fromdate, todate = GetDatesWorked() hours = GetHoursWorked() hourlyrate = GetHourlyRate() taxrate = GetTaxRate() fromdate = fromdate.strftime('%Y-%m-%d') todate = todate.strftime('%Y-%m-%d') # write the line of code that will assign to EmpDetail a pipe delimited string of fromdate, todate, empname, hours, hourlyrate and taxrate and a carriage return at the end # write the line of code that will write EmpDetail to the file # close file to save data # write the line of code that will close the file printinfo(DetailsPrinted) #*********************************************************************************************************************************************** Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
