Python(一)入门级员工管理系统

前言

halo!好久不见,很久没写博客,一直想要找回当初在学校里敲代码学习的状态,所以现在虽然做着简单枯燥的软测工作,但是也有开始学习python,下面就是最入门级的一个员工管理系统,算是对python基本语法学习完的交代。

代码

#员工管理系统

#定义一个员工信息字典
employee = {}

# 1、显示菜单
def show_menu():
    print("*" * 30)
    print("员工管理系统 v2.0")
    print("  1:添加员工信息")
    print("  2:删除员工信息")
    print("  3:编辑员工信息")
    print("  4:查看所有员工信息")
    print("  5:查看具体员工信息")
    print("  6:退出员工系统")
    print("*" * 30)

# 2、显示所有信息
def show_all_info():
    for em_number in employee:
        # print(employee)
        print("员工编号:" + em_number +
              ", 员工姓名:" + employee[em_number]['name'] +
              ", 员工薪水:" + employee[em_number]['salary'] +
              ", 员工性别:" + employee[em_number]['sex'])

#3、根据员工编号查看员工信息
def show_single_info():
    em_number = input("请输入要查看的员工编号:")
    em_name = employee[em_number]['name']
    em_salary = employee[em_number]['salary']
    em_sex = employee[em_number]['sex']
    print("姓名:" + em_name + " 薪水:" + em_salary + " 性别:" + em_sex)

# 4、新增员工
def add():
    em_number = input("请输入员工编号:")
    em_name = input("请输入员工姓名:")
    em_salary = input("请输入员工薪水:")
    em_sex = input("请输入员工性别:")
    em_info = {'name': em_name, 'salary': em_salary, 'sex': em_sex}
    employee[em_number] = em_info
    print("新增员工成功!请按4查看所有员工信息")

#5、编辑员工信息
def edit():
    em_number = input("请输入员工编号:")
    if em_number not in employee:
        print("您输入的员工编号不存在!")
        return
    new_name = input("请输入新的员工姓名:")
    new_salary = input("请输入新的员工薪水:")
    new_sex = input("请输入新的员工性别:")
    employee[em_number]['name'] = new_name
    employee[em_number]['salary'] = new_salary
    employee[em_number]['sex'] = new_sex
    print("编辑员工编号为" + em_number + "的员工信息成功")

#6、删除员工
def delete():
    em_number = input("请输入员工编号:")
    if em_number not in employee:
        print("您输入的员工编号不存在!")
        return
    del employee[em_number]
    print("删除员工编号为" + em_number + "的员工成功")

#main方法
def main():
    show_menu()
    while True:
        user_operate = input("请输入您的操作:")
        if user_operate == '1':
            add()
        elif user_operate == '2':
            delete()
        elif user_operate == '3':
            edit()
        elif user_operate == '4':
            show_all_info()
        elif user_operate == '5':
            show_single_info()
        elif user_operate == '6':
            print("欢迎下次登录员工管理系统!!")
            break
        else:
            print("您的操作有误,请重新操作!")
main()

你可能感兴趣的:(Python)