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.
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
Flowchart
To enlarge flowchart turn side navigation off, Click on
in the top navigation bar to change to 
Starter Code
Project 4.12
Print a payroll report.
Input
A file IN which each line has the form
<last name> <hourly wage> <hours worked>
Output
A report IN tabular format. Each line has the form
<last name> <hours worked> <total wages>
"""
# Take the INPUTs
SET fileName TO INPUT("Enter the file name: ")
# Open the data file read only
SET dataFile TO open(fileName, 'r')
# Read the data and OUTPUT the report
# Output header FOR report of the wages paid
OUTPUT("%-15s%6s%15s" % ("Name", "Hours", "Total Pay"))
# For each line from the data file
FOR line IN dataFile:
# Split line from data file into a list
SET dataList TO line.split()
# Assign data from list to variables with appropriate datatype
SET name TO dataList[0]
SET hours TO int(dataList[1])
SET payRate TO float(dataList[2])
# Calculate Total Pay
SET totalPay TO hours * payRate
# Output Name, Hours, & Total Pay FOR this line from the data file
OUTPUT("%-15s%6d%15.2f" % (name, hours, totalPay))
Data File
Lambert 34 10.50
Osborne 22 6.25
Giacometti 5 100.70