该题目是第一章第六题,编写了一个程序,使用户输入文件名(预先设定好的文本文件)并向终端输出报表,展示在给定的周期应该向每一位员工支付的工资(表格形式)
# Take the inputs
fileName = input("Enter the file name: ")
# Open the input file
inputFile = open(fileName, 'r')
# Read the data and print the report
print("%-15s%6s%15s" % ("Name", "Hours", "Total Pay"))
for line in inputFile:
dataList = line.split()
name = dataList[0]
hours = int(dataList[1])
payRate = float(dataList[2])
totalPay = hours * payRate
print("%-15s%6d%15.2f" % (name, hours, totalPay))
位雇员支付的工资。