While using this python program on cengage mindtap for programming exercise 4.12 it is not taking the
Fantastic news! We've Found the answer you've been seeking!
Question:
While using this python program on cengage mindtap for programming exercise 4.12 it is not taking the hours worked and multiplying it by the Total Pay of the person that is listed in a txt file. Enter the file name: test.txt Name Hours Total Pay Lennon 12 3.33 McCartney 57 7.00 Harrison 11 9.10 Starr 3 4.13 filename = input("Enter the file name: ") # input the filename from the user # declare lists for storing names, hours worked and total pays names = [] hours = [] totalPay = [] # open the file with open(filename, "r") as file: lines = file.readlines() # read lines # iterate over everyline for line in lines: line = line.split() # split the line by space to get a list of words names.append(line[0]) # add the name from the line to the list hours.append(int(line[1])) # append the integer(hours) from the line to the hours list totalPay.append(float(line[2]))# append the float value of the total pay from the line to the totalPay list print() # print the header in the format print(f'{"Name":14s}{"Hours":9s}{"Total Pay":13s}') # iterate over the created lists and print the details in formatted manner for name, hour, pay in zip(names, hours, totalPay): print(f"{name:15s}{hour:4d}{pay:13.2f}")
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: