动动手第63讲,第一次敲这么多代码
class Member:def __init__(self):
self.names = []
self.jobs = {}
self.grades = {}
self.years = {}
self.uids = {}
self.salarys = {}
self.counts = 0
class SalaryMixin:
def salary(self,grade,year,job):
if job == "E":
return 3000+500*int(grade)+50*int(year)
if job == "T":
return 4000+800*int(grade)+100*int(year)
if job == "M":
return 5000+1000*(int(grade)+int(year))
class Manage:
def log_in(self):
m = Member()
s = SalaryMixin()
num = 10000 + m.counts
name = input("姓名:")
while name in m.names:
name = input("该姓名已存在,请重新录入:")
else:
m.names.append(name)
m.uids = num
job = input("职位(E.普通员工;T.组长;M.经理):")
m.jobs = job
year = input("工龄:")
m.years = year
grade = input("级别")
if job == "E":
while int(grade) > 10 or int(grade) < 1:
grade = input("级别不正确,请重新输入:")
if job == "T":
while int(grade) > 6 or int(grade) < 1:
grade = input("级别不正确,请重新输入:")
if job == "M":
while int(grade) > 3 or int(grade) < 1:
grade = input("级别不正确,请重新输入:")
m.grades = grade
m.counts += 1
salary = s.salary(grade,year,job)
m.salarys = salary
print(f"录入成功!姓名:{name},工号:{num},薪资:{salary}")
def staff_search(self):
m =Member()
uid = input("请输入工号")
try:
name = m.uids
job = m.jobs + m.grades
salary = m.salarys
except:
print("该员工不存在")
else:
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
def job_search(self):
m = Member()
job = input("职位(E.普通员工;T.组长;M.经理):")
sums = 0
_ = []
if job == "E":
for each in m.names:
if m.jobs == "E":
sums += 1
_.append
print(f"当前普通员工共有{sums}人")
for each in _:
print(f"{m.uids}-each")
if job == "T":
for each in m.names:
if m.jobs == "T":
sums += 1
_.append
print(f"当前组长共有{sums}人")
for each in _:
print(f"{m.uids}-each")
if job == "M":
for each in m.names:
if m.jobs == "M":
sums += 1
_.append
print(f"当前经理共有{sums}人")
for each in _:
print(f"{m.uids}-each")
def upgrade(self):
m = Member()
s = SalaryMixin()
uid = input("请输入工号:")
sums = 0
try:
name = m.names)]
job = m.jobs + m.grades
salary = m.salarys
except:
print("该员工不存在")
else:
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if m.jobs == "E":
grade = input("请输入需要增加的级数")
sums = int(m.grades) + int(grade)
while sums > 19:
grade = input("级别错误,请输入需要增加的级数")
sums = int(m.grades) + int(grade)
else:
if sums < 11:
print("升级成功")
salary = int(salary) + 500 * int(grade)
job = m.jobs + str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if sums > 10 and sums < 17:
print("升级成功")
salary = s.salary(sums-10,m.years,"T")
job = "T"+str(sums-10)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if sums > 16 and sums < 20:
print("升级成功")
salary = s.salary(sums-16,m.years,"M")
job = "M"+str(sums-16)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if m.jobs == "T":
grade = input("请输入需要增加的级数")
sums = int(m.grades) + int(grade)
while sums > 9:
grade = input("级别错误,请输入需要增加的级数")
sums = int(m.grades) + int(grade)
else:
if sums < 4:
print("升级成功")
salary = int(salary) + 800 * int(grade)
job = m.jobs + str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if sums > 3 and sums < 10:
print("升级成功")
salary = s.salary(sums-3,m.years,"M")
job = "M"+str(sums-3)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if m.jobs == "M":
grade = input("请输入需要增加的级数")
sums = int(m.grades) + int(grade)
while sums > 3:
grade = input("级别错误,请输入需要增加的级数")
sums = int(m.grades) + int(grade)
else:
print("升级成功")
salary = int(salary) + 1000 * int(grade)
job = m.jobs + str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
def downgrade(self):
m = Member()
s = SalaryMixin()
uid = input("请输入工号:")
sums = 0
try:
name = m.names)]
job = m.jobs + m.grades
salary = m.salarys
except:
print("该员工不存在")
else:
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if m.jobs == "E":
grade = input("请输入需要减少的级数")
sums = int(m.grades) - int(grade)
while sums < 1:
grade = input("级别错误,请输入需要增加的级数")
sums = int(m.grades) + int(grade)
else:
print("降级成功")
salary = int(salary) - 500 * int(grade)
job = m.jobs + str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if m.jobs == "T":
grade = input("请输入需要减少的级数")
sums = int(m.grades) - int(grade) + 10
while sums < 1:
grade = input("级别错误,请输入需要增加的级数")
sums = int(m.grades) + int(grade)
else:
if sums > 10:
print("降级成功")
salary = int(salary) - 800 * int(grade)
job = m.jobs + str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if sums < 11:
print("降级成功")
salary = s.salary(sums,m.years,"E")
job = "E"+str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if m.jobs == "M":
grade = input("请输入需要减少的级数")
sums = int(m.grades) - int(grade) + 16
while sums < 1:
grade = input("级别错误,请输入需要增加的级数")
sums = int(m.grades) + int(grade)
else:
if sums > 16:
print("降级成功")
salary = int(salary) - 1000 * int(grade)
job = m.jobs + str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if sums > 10 and sums < 17:
print("降级成功")
salary = s.salary(sums-10,m.years,"T")
job = "T"+str(sums-10)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
if sums < 11:
print("降级成功")
salary = s.salary(sums,m.years,"E")
job = "E"+str(sums)
print(f"{name},工号:{uid},当前职位:{job},当前薪资:{salary}")
while True:
command = input("1.录入;2.查询;3.升级;4.降级;5.退出:")
m = Manage()
if command == "1":
m.log_in()
if command == "2":
search = input("1.员工查询;2.职位查询:")
if search == "1":
m.staff_search()
else:
m.job_search()
if command == "3":
m.upgrade()
if command == "4":
m.downgrade()
if command == "5":
break
里面还有好多bug没改,好多要严谨的地方我都懒得敲了{:10_269:} {:5_106:} {:10_275:} sfqxx 发表于 2023-5-3 11:39
{:5_92:} liuhongrun2022 发表于 2023-5-3 11:41
{:5_109:}
页:
[1]