我正在编写程序来输出计算工资单的表格。 它是从导入的文件中读取的。
我用来测试的文件包含:
这里的想法是取每条线并将其拆分,然后按位置按位置打印我需要的东西。 以下是我认为包含该问题的代码部分:
def getFile():
filename = input("Please enter the employee file name: ")
print()
infile = open(filename, "r")
return infile
def outputs(infile):
paylist = []
count = 0
for lines in infile:
individual = lines.split(",")
for pos in individual:
first = ("{0:7}".format (individual[0]))
print(first, end = "")
last = ("{0:12}".format(individual[1]))
print(last, end = "")
hours = ("{0:6}".format(individual[2]))
print(hours, end = "")
wage = ("{0:6}".format(individual[3]))
print ("$",wage, end = "")
当我运行它时,它输出所有正确的值,但是输出
4次答案 0 :(得分:0)
outputs()
的内环是罪魁祸首。删除它。
def outputs(infile):
paylist = []
count = 0
for lines in infile:
individual = lines.split(",")
first = ("{0:7}".format (individual[0]))
print(first, end = "")
last = ("{0:12}".format(individual[1]))
print(last, end = "")
hours = ("{0:6}".format(individual[2]))
print(hours, end = "")
wage = ("{0:6}".format(individual[3]))
print ("$",wage, end = "")