【发布时间】:2020-08-31 05:31:04
【问题描述】:
我仍然被困在这里,我正在尝试打印工资单。我想参考employee_info.txt根据员工编号获取时间记录。但我的问题是 rate 在 employee_info 中,days_work 在 time_record.txt 中,主要问题是它只打印一个人或一个月。
employee_info.txt 包含员工编号、姓氏、姓名、部门、每小时费率
201911007,James,Butt,Accounting,365;
201203008,Josephine,Darakjy,Marketing,365;
199710014,Art,Venere,Human Resources,750;
201612010,Lenna,Paprocki,Marketing,565;
201710017,Donette,Foller,Admin,450;
201701013,Simona,Morasca,Finance,450;
201011003,Mitsue,Tollner,Marketing,750;
201409015,Leota,Dilliard,Finance,365;
199512017,Sage,Wieser,MIS,750;
199708003,Kris,Marrier,Admin,750;
20011234, Robert, John, Finance, 120;
time_record.txt 包含员工编号、月份(数字)、工作天数
201911007,1,28;
201203008,1,28;
199710014,1,28;
201612010,1,28;
201710017,1,28;
201701013,1,28;
201011003,1,28;
201409015,1,28;
199512017,1,28;
199708003,1,28;
201911007,2,28;
201203008,2,28;
199710014,2,28;
201612010,2,28;
201710017,2,28;
201701013,2,28;
201011003,2,28;
201409015,2,28;
199512017,2,28;
199708003,2,28;
201911007,3,10;
201203008,3,27;
199710014,3,28;
201612010,3,19;
我的代码是。
def printing(last_name,first_name,month,time_record_empno,emp_no,department,rate_per_day,days_work):
emp_no = [] #employee number as reference
first_name = []
last_name = []
department = []
rate_per_day = []
time_record_empno=[] # employee number
month=[]
days_work=[]
with open("employee_info.txt", 'r') as file:
for dl in file:
dl = dl.strip()
if len(dl) >= 1:
li = dl.split(",")
emp_no.append(li[0].strip())
first_name.append(li[1].strip())
last_name.append(li[2].strip())
department.append(li[3].strip())
rate_per_day.append(li[4].upper().rstrip(';'))
with open("time_record.txt", 'r') as files:
for dln in files:
dln = dln.strip()
if len(dln) >= 1:
lii = dln.split(",")
MR_empno.append(lii[0].strip())
month.append(lii[1].strip())
days_work.append(lii[2].rstrip(';'))
for mm, mr, ll, nn, emp, dep, rat, hr in zip(month, empno, last, name, mrem, depart, rates, hours):
files = open('payslip.txt', 'w')
print("*" * 160)
print(f"Payslip for the MONTH OF:{mm}")
print(f"Employee No.{mr}Employee Name:{ll}, {nn} ")
print(f"Department:{dep}")
print(f"Rate Per Day:{rat}No. of Hours Worked:{hr} ")
gross = int(rat)*int(hr)
print(f"Gross Pay:{gross}")
print("*" * 160)
有解决这个问题的建议吗?谢谢。
【问题讨论】:
-
zip() 中的小时数是多少?
-
抱歉,这是days_work。
-
你能修复函数内部代码的缩进吗?
标签: python-3.x list reference text-files element