Question

Employees.txt John Doe,40 Sally Buck, 45 2) Write some Python codes that processes a file of employees and calculates their weekly pay (11). The file will contain 2 fields (first name and last name, and number of hours worked, separated by a comma): John Doe,40. Download a file called Employees.txt from BlackBoard. Open the file and read each line, calculate the weekly salary and output a formatted table containing two columns (1st column: 30 characters following by the pay) Write a function called GrossPay0 which is passed the hours worked (read from the file). The function should calculate and return the gross pay of each using a rate of S15.25 per hour. Call this function in your processing loop COS 120 Introduction to Programming Name the file EmployeePay.py. Upload the source code and screen shot of the program output to Blackboard. The output should look as follows COS-120 [CAUserslmicha\PycharmProjects)CoS-120] - .,.Employ File Edit View Navigate Code Refactor Run Iools VCS Window Help COS-120EmployeePay.py EmployeePay c:\users\michalve n叭cos-120\scripts\python.exe Name John Doe Run: c Pay $610.00 $686.25 lSally Buck Process finished with exit code 0 Terminal Python Console · 4: Run TODO Event Log 6:12 CRLF UTF-8

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

Python Code: Keep the Code and Employees.txt in same folder

def GrossPay(hrs):

               return hrs*15.25

print("%-30s%s"%("Name", "Pay"))

with open("Employees.txt", 'r') as f:

               for line in f:

                              Name, hrs = line.split(',')

                              hrs = int(hrs)

                              print("%-30s$%.2f"%(Name, GrossPay(hrs)))

OUTPUT:

Name John Doe Sally Buck Pay $610.00 $686.25

Add a comment
Know the answer?
Add Answer to:
Employees.txt John Doe,40 Sally Buck, 45 2) Write some Python codes that processes a file of...
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
  • (Python) Write a program called sales.py that uses a list to hold the sums of the...

    (Python) Write a program called sales.py that uses a list to hold the sums of the sales for each month. The list will have 12 items with index 0 corresponds with month of “Jan”, index 1 with month “Feb”, etc. o Write a function called Convert() which is passed a string which is a month name (ex. “Jan”) and returns the matching index (ex. 0). Hint – use a list of strings to hold the months in the correct order,...

  • Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The...

    Python 3 Question Please keep the code introductory friendly and include comments. Many thanks. Prompt: The owners of the Annan Supermarket would like to have a program that computes the weekly gross pay of their employees. The user will enter an employee’s first name, last name, the hourly rate of pay, and the number of hours worked for the week. In addition, Annan Supermarkets would like the program to compute the employee’s net pay and overtime pay. Overtime hours, any...

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