Question

The Payroll Department keeps a list of employee information for each pay period in a text...

The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hourly wage> <hours worked>

Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period.

The report should be in tabular format with the appropriate header.

Each line should contain:

An employee’s name

The hours worked

The wages paid for that period.

An example of the program input and output is shown below:

Enter the file name: data.txt

Name            Hours      Total Pay
Lambert            34         357.00
Osborne            22         137.50
Giacometti          5         503.50 

Python code please.

3 1
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1
file_name = input('Enter input file name: ')

# print the header on terminal
print('\n%-15s%-10s%-10s' % ('Name', 'Hours', 'Total Pay'))

# open the file and iterate line by line
for line in open(file_name):
    line = line.strip()

    # if line is not blank
    if line != '':
        # split the line and capture each group
        (nm, wage, hours) = line.split()

        # name is in string, while wage and hours next
        # to be converted form stirng to float
        wage = float(wage)
        hours = int(hours)
        pay = wage * hours

        print('%-15s%-10d%-10.2f' % (nm, hours, pay))


======================

data.txt:
Lambert 10.5 34 
Osborne 6.25 22
Giacometti 100.7 5

main py E O saved 1ile_name inputEnter input file name: 3 # print the header on terminal python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux Files D main.py Repl.it: Stopped data.txt print(\n%-15s%-10s%-10s, % (Name, Hours, Total Pay)) Enter input file name: data.txt 6 # open the file and iterate line by line 7 for line in open(file_name): Name Lambert Osborne Giacometti Total Pay 357.00 137.50 503 .5Θ 34 ine line.strip() # if line is not blank if line 1: 10 # split (nm, wage, hours)line.split) the line and capture each group 12 13 15 16 17 18 19 20 21 # name is in string, while wage and hours next # to be converted form stirng to float wage-float (wage) hours int (hours) paywagc hours print(%-155%-100%-10.2f. % (nm, hours, pay) In case of any doubts, please ask in comments. If the answer helps you, please upvote. I am in great need of upvotes. Thanks!

Add a comment
Know the answer?
Add Answer to:
The Payroll Department keeps a list of employee information for each pay period in a text...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • The Payroll Department keeps a list of employee information for each pay period in a text...

    The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain: An employee’s name The hours worked The wages paid...

  • Programming Exercise 4.12 The Payroll Department keeps a list of employee information for each pay period...

    Programming Exercise 4.12 The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain:...

  • I am having a hard time with my program to assignment 4.12. Here are the instructions:...

    I am having a hard time with my program to assignment 4.12. Here are the instructions: The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report...

  • Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee...

    Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee number, employee name, hourly pay rate, regular hours worked and overtime hours worked. The company pays its employees weekly, according to the following rules: regular pay = regular hours worked × hourly rate of pay overtime pay = overtime hours worked × hourly rate of pay × 1.5 total pay = regular pay + overtime pay Your program is to read the input data...

  • You are to write a program that will process employees and their pay. For each employee...

    You are to write a program that will process employees and their pay. For each employee the program will read in an employee’s name and hourly pay rate. It should also read in the number of hours worked each day for 5 days and calculate his or her total number of hours worked. You must read the hours using a loop. The program should output the employee’s name, gross pay, total withholding amount and net pay. Withholding is made up...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • In C program Consider a file that contains employee records, called "empstat.txt." The data for each...

    In C program Consider a file that contains employee records, called "empstat.txt." The data for each employee consist of the employee’s last name (up to 20 characters), employee id number (up to 11 characters), gross pay for the week (double), taxes deducted (double) for the week, and net pay (double) for the week. Create a struct to hold the employee information. Write a void function called writeEmpFile that prompts the user to enter last name, id number, gross pay and...

  • write this program in Java Problem 5. (30 Points) Write a program that reads employee work...

    write this program in Java Problem 5. (30 Points) Write a program that reads employee work data from a text file employee.txt), and then calculates payroll information based on this file and store them into a new text file called payroll.txt. The employee. txt file contains one line of text for each employee. Each line consists of the following data (delimited by tabs): employee's name, employee's hourly wage rate, hours worked Monday, hours worked Tuesday, hours worked Wednesday, hours worked...

  • in csis 152 style python programming language Read the initial employee information from a text file...

    in csis 152 style python programming language Read the initial employee information from a text file and store the employee information into a list of sublists called empRoster. Each sublist should contain [empID, name, payrate,hours] Here's an example of how empRoster will look: 111, "Sally Smith", 10, 401, 1222, "Bob Brown", 10, 42]1 The text file will be structured as shown below, where each line contains the employee id, employee name, payrate and hours. Each entry on the line is...

  • using c++ output format should look this but use employee id,hours worked and pay rate and...

    using c++ output format should look this but use employee id,hours worked and pay rate and the total should be calculated. for example employee id:1234 hours work:29.3 pay rate:16.25 administrative, office and field should be outputted as well too. Using a structure, and creating three structure variables, write a program that will calculate the total pay for thirty (30) employees. (Ten for each structured variable.) Sort the list of employees by the employee ID in ascending order and display their...

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
ADVERTISEMENT