Question

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 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

THE OUTPUT NEEDS TO BE WHAT IS IN RED. PLEASE HELP!! MY PROGRAM KEEPS GIVING ME THE WRONG OUTPUT

  • Output Enter input file name: test.txt Hours w Name Lennon McCartney Harrison Starr Total Pay 39.96 399.00 100.10 12.39 Resul

HERES WHAT I HAVE:

# 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 = float(hours)
pay = wage * hours

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

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

print('\n%-15s%-10s%-10s' % ('Name', 'Hours', 'Total Pay'))

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

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

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

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

Activities 2 Text Editor Fri 14:12 Open & detials.txt -/Desktop Save wages.py detials.txt Lennon 12 3.33 McCartney 57 7.0 Har

Activities 2 Text Editor Fri 14:12 Open A wages.py Desktop Save = 60 detials.txt wages.py print(\n%-155%-105%-105 % (Name

Activities Terminal Fri 14:12 deepika@deepika-TravelMate-P243-M: -/Desktop File Edit View Search Terminal Help deepika@deepik

If you have any doubts please comment and please don't dislike.

Add a comment
Know the answer?
Add Answer to:
I am having a hard time with my program to assignment 4.12. Here are the instructions:...
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
  • 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:...

  • 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 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...

  • I am having trouble with my Python code in this dictionary and pickle program. Here is...

    I am having trouble with my Python code in this dictionary and pickle program. Here is my code but it is not running as i am receiving synthax error on the second line. class Student: def__init__(self,id,name,midterm,final): self.id=id self.name=name self.midterm=midterm self.final=final def calculate_grade(self): self.avg=(self.midterm+self.final)/2 if self.avg>=60 and self.avg<=80: self.g='A' elif self.avg>80 and self.avg<=100: self.g='A+' elif self.avg<60 and self.avg>=40: self.g='B' else: self.g='C' def getdata(self): return self.id,self.name.self.midterm,self.final,self.g CIT101 = {} CIT101["123"] = Student("123", "smith, john", 78, 86) CIT101["124"] = Student("124", "tom, alter", 50,...

  • This is my current output for my program. I am trying to get the output to...

    This is my current output for my program. I am trying to get the output to look like This is my program Student.java import java.awt.GridLayout; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import javax.swing.JFileChooser; public class Student extends javax.swing.JFrame {     BufferedWriter outWriter;     StudentA s[];     public Student() {         StudentGUI();            }     private void StudentGUI() {         jScrollPane3 = new javax.swing.JScrollPane();         inputFileChooser = new javax.swing.JButton();         outputFileChooser = new javax.swing.JButton();         sortFirtsName = new...

  • I am really struggling with this assignment, can anyone help? It is supposed to work with...

    I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...

  • i am having issues correcting an error in my program here is my code: #include <iostream>...

    i am having issues correcting an error in my program here is my code: #include <iostream> // define libraries #include <fstream> using namespace std; // Variable definitions: ifstream infp; // file handler enum Tokens {INT_LIT, IDENT, ASSIGN_OP, ADD_OP, SUB_OP, MUL_OP, DIV_OP, LEFT_PAREN, RIGHT_PAREN, LETTER, DIGIT, UNKNOWN,ENDFILE}; Tokens nextToken; // nextToken read from the file. int charClass; // char class char lexeme [100]; // number of characters per line char nextChar; // next char read from the file int lexLen; //...

  • Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit...

    Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit 1 zip file containing 4 files below to iLearn by the deadline. [30 points] ● 3 JAVA Files: TableBmiPro.java, MyOwnIdea.java. DiceRoll.java [24 points] ● 1 File: Make a document that shows the screen captures of execution of your programs and learning points in Word or PDF. Please make sure you capture at least 2 executions for 1 program, so 6 screen captures and one...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • Hi I am using python and I keep getting this error with my code. Traceback (most...

    Hi I am using python and I keep getting this error with my code. Traceback (most recent call last): ['1'] Traceback (most recent call last): File "/Users/isabellawelch/Python ish/shuffle.py", line 86, in <module> emp = Employee(emp_data[0], emp_data[1], emp_data[2], emp_data[3], emp_data[4]) IndexError: list index out of range What does it mean and how do i fix it?? from tkinter import Tk, Label, Button, Entry, END employees = [] class Employee: def __init__(self, empno, name, addr, hwage, hworked): self.empno = empno self.name =...

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