Question

Create a script that reads in the attached emp.txt file and outputs a file with the...

Create a script that reads in the attached emp.txt file and outputs a file with the net pay of each employee. Incorporate the overtime and net pay rules from the previous assignments. Also, create a separate file which states the employee with the highest net pay and the employee with the lowest net pay. The structure of emp.txt is the following: employee_id, hourly_rate, hours_worked, years_of_service Overtime rules: To earn overtime the employee must have worked for the company for at least 2 years AND must have worked over 40 hours If the employee worked over 50 hours they receive an additional 50 to be added to grossPay If the employee has worked over 40 hours but has not worked for the company for at least 2 years they do not receive overtime. Use the following formula to determine how much overtime the user worked overtime = - 40 Calculate the gross pay with the following formula grossPay = (overtime * * 2) + (( - overtime) * ) Net Pay rules: subtract 39% from gross pay emp.text file - https://docs.google.com/document/d/1bw6N2jU1fjfwum-g_VvZKtLGwI4UtMXd39uOuFYf0kg/edit?usp=sharing Python 3.7

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import sys

high = ""

low = ""

def write_output_file(line, file):

with open(file, "a") as myfile:

myfile.write(line + "\n")

def execute(line):

global high

global low

(employee_id, hourly_rate, hours_worked, years_of_service) = line.split(",")

payment = float(hourly_rate) * int(hours_worked)

if int(hours_worked) > 50:

payment = payment+50

if int(years_of_service) > 2 and int(hours_worked) > 40:

overtime = int(hours_worked) - 40

payment = payment + (overtime**2) - overtime

net_pay = payment - (payment * 0.39)

if high:

(emp_id, net_pay2) = high.split(",")

if float(net_pay2) < net_pay:

high = "%s,%s" % (employee_id, str(net_pay))

else:

high = "%s,%s" % (employee_id, str(net_pay))

if low:

(emp_id, net_pay2) = low.split(",")

if float(net_pay2) > net_pay:

low = "%s,%s" % (employee_id, str(net_pay))

else:

low = "%s,%s" % (employee_id, str(net_pay))

result = "%s,%s" % (employee_id, str(net_pay))

return result

def process_file(file_name):

with open(file_name, 'rt') as myfile:

for line in myfile:

write_output_file(execute(line), "output.txt")

write_output_file(high, "high_low.txt")

write_output_file(low, "high_low.txt")

if __name__=='__main__':

if len(sys.argv) > 1 and sys.argv[1]:

try:

process_file(sys.argv[1])

except Exception as e:

print(str(e))

else:

print('provide the full path of the file as argument')

Add a comment
Know the answer?
Add Answer to:
Create a script that reads in the attached emp.txt file and outputs a file with the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Text file containing the following data (without the headings): Name            Wage      Hours Callaway, G 16.00       40 Hanson, P     15.00      48 Lasard, D      16.50      35 Stillman,...

    Create a Text file containing the following data (without the headings): Name            Wage      Hours Callaway, G 16.00       40 Hanson, P     15.00      48 Lasard, D      16.50      35 Stillman, W   18.00      50 Write a C++ program that uses the information in the file to produce the following pay report for each employee: Name, Pay Rate, Hours, Regular Pay, Overtime Pay, Gross Pay       Compute regular pay as  any hours worked up to and including 40 hours multiplied by the pay rate. Compute overtime...

  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

  • Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class...

    Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class (which inherits from the Employee class) for a basic payroll program to compute the net pay salary of hourly based employees. Your program should also find the average net pay for a small company. To define the class, include the appropriate data members, member functions, constructors, and access modifiers. For simplicity, use a constant tax rate of 30% to compute the tax amount. Employees...

  • Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main()...

    Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it...

  • "Multiple Function Returns Using Memory Pointers" Contents of employee.dat... copy paste and create a file (employee.dat)...

    "Multiple Function Returns Using Memory Pointers" Contents of employee.dat... copy paste and create a file (employee.dat) 123-45-6789 Kirk James 44.7 88.99 0.0175 124-89-0007 Bond Jane 45.6 65.75 0.04 405-77-8911 Puff Blossom 40 33.88 0.03 405-10-9871 Puff Buttercup 41.2 45.66 0.047 223-03-8761 Puff Bubbles 37.8 33.44 0.015 980-11-2201 Joneski Kasey 23.1 10.77 0.033 115-88-7619 Crooke I.M.A. 25.4 88.75 0.02 777-00-1232 Smith Alias 43.5 22.3 0.034 345-89-0022 DeMann Stan 56.7 29.45 0.065 210-37-1192 Jones Jeane 48.9 20.33 0.025 103-22-4321 Smith Alias 33.5...

  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

  • Exercise 1 A program was created that outputs the following unto the console: Hello! What is...

    Exercise 1 A program was created that outputs the following unto the console: Hello! What is your name: Hello, Jane Doe! Using this program, we can help you determine you pay for the week! Please enter the hours you worked this week: 20 Next, please enter your rate of pay: 10 Calculating… you will make $ 200 by the end of the week! Here is the code for that program (you should have written a close variant of this last...

  • JAVA Programming . Description: For an unknown number of employees: prompt and receive payroll data; calculate...

    JAVA Programming . Description: For an unknown number of employees: prompt and receive payroll data; calculate gross pay, taxes owed, and net pay; and display a pay stub. Input : Prompt and receive input from the user for the following:  /// Employee’s First and Last Name  /// Hours Worked  /// Pay Rate  /// Overtime Rate Multiplier ** For the Employee’s First and Last Name:  Both data items must be read in one prompting into one...

  • Introduction to computer class, Java programming through eclipse: Ue the following criteria to create the code:...

    Introduction to computer class, Java programming through eclipse: Ue the following criteria to create the code: SALARY Input first and last name - Output the names last, first in your output - Make the federal withholding rate a constant 20% (not an input value) No state tax Generate two new values: regular pay and overtime pay - 40 hours workedor less - Regular pay is pay rate * hours worked - Overtime pay is 0 Otherwise - Regular pay is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT