python实现后台员工管理系统

# 后台员工管理系统 文件1:yuangongshuju
dict = {'1001': {'empName': '王子', 'sex': '男', 'age': '17'},
'1002': {'empName': '皇上', 'sex': '男', 'age': '37'},
'1003': {'empName': '公主', 'sex': '女', 'age': '17'},
}

def menu():
""""进入菜单页面"""
print("*" * 10+"后台员工管理系统"+ "*" * 10)
print("1、查询所有员工")
print("2、添加员工信息")
print("3、修改员工信息")
print("4、删除员工信息")
print("5、退出员工系统")
print("*" * 40)

def all():
"""显示员工信息"""
print("显示所有员工信息===>")
if len(list(dict.keys())) == 0:
print("当前没有任何的员工信息,请先选择操作 2,添加员工!!!")
return
print("-" * 40)
for people in ["empID", "empName", "sex", "age"]:
print(people, end="\t\t")
print("")
print("-" * 40)
for word in dict.items():
print("%s\t\t%s\t\t%s\t\t\t%s" % (word[0],
word[1]['empName'],
word[1]['sex'],
word[1]['age']))
print("-" * 40)


def tianjia():
"""添加员工信息"""
print("添加员工===>")
dict_id = input("请输入要添加员工的工号:")
all_id = list(dict.keys())
if dict_id in all_id:
print("员工工号已存在,不能重复添加!!!")
return
dict_name = input("请输入要添加员工的姓名:")
dict_sex = input("请输入要添加员工的性别:")
dict_age = input("请输入要添加员工的年龄:")
tianjia = {"empName": dict_name, "sex": dict_sex, "age": dict_age}
dict[dict_id] = tianjia
print("工号为 %s 的员工信息添加成功!!!" % dict_id)



def update():
"""修改员工信息"""
print("修改员工===>")
employ_id = input("请输入你要修改的员工的工号")
all_id = list(dict.keys())
if employ_id not in all_id:
print("该员工工号不存在,不能进行修改!!!")
return
new_name = input("姓名是:%s 修改后的姓名:" % dict[employ_id]['empName'])
new_sex = input("性别是:%s 修改后的性别:" % dict[employ_id]['sex'])
new_salary = input("年龄是:%s 修改后的年龄:" % dict[employ_id]['age'])

if new_name != "":
dict[employ_id]['empName'] = new_name
if new_sex != "":
dict[employ_id]['sex'] = new_sex
if new_salary != "":
dict[employ_id]['age'] = new_salary
print("工号为 %s 的员工信息修改成功!!!" % employ_id)


def delete():
"""删除员工信息"""
print("删除员工===>")
dict_id = input("请输入你要删除的员工的工号")
all_id = list(dict.keys())
if dict_id not in all_id:
print("该员工工号不存在,不能进行删除!!!")
return
else:
del dict[dict_id]
print("工号为 %s 的员工信息删除成功!!!" % dict_id)

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
import yuangongshuju
#导入文件1:yuangongshuju
while True:
yuangongshuju.menu()
action_str = input("请输入您的操作:")
if action_str == "1": \
# 1.显示所有员工信息
yuangongshuju.all()
elif action_str == "2":
# 2.添加员工信息
yuangongshuju.tianjia()
elif action_str == "3":
# 3.修改员工信息
yuangongshuju.update()
elif action_str == "4":
# 3.删除员工信息
yuangongshuju.delete()
elif action_str == "5":
# 5.退出系统
print("欢迎您再次使用员工管理系统!!!")
break
else:
# 输入其他任意数字
print("您输入的有误,请重新输入:")
posted @ 2021-01-09 09:44  渡赢  阅读(1137)  评论(0编辑  收藏  举报