人力系统 全职员工,兼职员工 属性:工号,姓名,全职月薪,兼职日薪、每月工作天数 方法:打印信息,计算月收入
# 人力系统
# 全职员工,兼职员工
# 属性:工号,姓名,全职月薪,兼职日薪、每月工作天数
# 方法:打印信息,计算月收入
class Employee:
def __init__(self, s_name, s_id):
self.s_name = s_name
self.s_id = s_id
def print_info(self):
print("%s\t%s" % (self.s_id, self.s_name))
class FullTimeEmployee(Employee):
def __init__(self, s_name, s_id, m_salary):
super().__init__(s_name, s_id)
self.FullTimeSalary = float(m_salary)
def print_salary(self):
print("salary:%.2f" % self.FullTimeSalary)
class PartTimeEmployee(Employee):
def __init__(self, s_name, s_id, d_salary, day):
super().__init__(s_name, s_id)
self.d_salary = float(d_salary)
self.day = int(day)
def print_salary(self):
PartTimeSalary = self.day * self.d_salary
print("salary:%.2f" % PartTimeSalary)
i = 1
f = 1
while 1:
print("""please select the service you need
1.add employee
2.print someone's info and salary
3.print all info
4.exit""")
mode = input()
if mode == '1': # 添加员工
repeat = 0
s_class = input("is he full-time or part-time:(f/p)")
if s_class == 'f': # 添加全职员工
s_id = input("input his id:")
for j in range(1, i):
if s_id == eval('f_employee' + str(j)).s_id:
print("this id has been used!")
repeat = 1
break
if repeat != 1: # id不重复
s_name = input("input his name:")
m_salary = input("input his monthly salary:")
locals()['f_employee' + str(i)] = FullTimeEmployee(s_name, s_id, m_salary)
print("create success!")
i = i + 1
elif s_class == 'p': # 添加兼职员工
s_id = input("input his id:")
for j in range(1, f):
if s_id == eval('p_employee' + str(j)).s_id:
print("this id has been used!")
repeat = 1
break
if repeat != 1: # id不重复
s_name = input("input his name:")
d_salary = input("input his daily salary:")
day = input("input days he worked:")
locals()['p_employee' + str(f)] = PartTimeEmployee(s_name, s_id, d_salary, day)
print("create success!")
f = f + 1
else:
print("error,try again!")
elif mode == '2':
selected = 0
u_class = input("is he full-time or part-time:(f/p)")
if u_class == 'f':
u_id = input("input his id:")
for j in range(1, i):
if u_id == eval('f_employee' + str(j)).s_id:
selected = 1
eval('f_employee' + str(j)).print_info()
eval('f_employee' + str(j)).print_salary()
break
if selected == 0:
print("unselected,try again!")
elif u_class == 'p':
u_id = input("input his id:")
for j in range(1, f):
if u_id == eval('p_employee' + str(j)).s_id:
selected = 1
eval('p_employee' + str(j)).print_info()
eval('p_employee' + str(j)).print_salary()
break
if selected == 0:
print("unselected,try again!")
else:
print("error,try again!")
elif mode == '3':
print("Full-time Employee")
for j in range(1, i):
eval('f_employee' + str(j)).print_info()
eval('f_employee' + str(j)).print_salary()
print("Part-time Employee")
for j in range(1, f):
eval('p_employee' + str(j)).print_info()
eval('p_employee' + str(j)).print_salary()
elif mode == '4':
exit()
else:
print("error,try again!")