Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5 .Implement a function payroll() that takes two string parameters the first of

ID: 639478 • Letter: 5

Question

5 .Implement a function payroll() that takes two string parameters the first of which represents the name of an input file and the second of which represents the name of an output file. The input file contains lines with the following format: hours pay_rate where hours is an integer representing a number of hours worked and pay_rate is a floating point value representing the pay rate per hour. There will be some whitespace between the two values, although you may not make any assumptions about how much or what type. The function reads the input file line by line, computing the total pay (i.e. the product of the hours times the pay_rate -- we are not assuming overtime is computed for any of the values) and writing each amount to a newline in the output file. If the file is empty, the function should not write any numbers to the output file. Note that the strings read from the file will need to be evaluated before you can use them for computations. The following shows what the function would return when called on several sample files found in the zip file containing the assignment template. The output files produced are also in the zip file:

Explanation / Answer

def payroll( input , output):
   with open(output, 'w') as w:
       with open(input, 'r') as f:
           for line in f:
               nums = line.split()
               w.write(str((int(nums[0])*float(nums[1])))+ ' ')
          
  

payroll("input.txt", "output.txt")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote