天天看點

Python指令行版本的員工管理系統

# 練習
#     - 做指令行版本的員工管理系統
#     - 功能:
#         四個:
#             1.查詢
#                 - 顯示目前系統當中的所有員工
#             2.添加
#                 - 将員工添加到目前系統中
#             3.删除
#                 - 将員工從系統當中删除
#             4.退出
#                 - 退出系統
#     - 員工資訊要儲存到哪裡? 清單,在系統中應該有一個清單,專門用來儲存所有員工資訊的



# 顯示系統歡迎資訊
print('-'*20,'歡迎使用員工管理系統','-'*20)
# 建立清單儲存員工資訊,員工的資訊以字元串的形式統一儲存到清單
emps = ['孫悟空\t18\t男\t花果山','豬八戒\t28\t男\t高老莊']
# 建立一個死循環
while True : 
    # 顯示使用者選項
    print('請選擇要做的工作:')
    print('\t1、查詢員工')
    print('\t2、添加員工')
    print('\t3、删除員工')
    print('\t4、退出系統')
    user_choose = input('請選擇[1-4]:')
    print('-'*20)
    # 根據使用者的選擇做相應的處理
    if user_choose == '1' :
        # 查詢員工
        # 列印表頭
        print('\t序号\t姓名\t年齡\t性别\t住址')
        # 建立一個變量,表示員工的序号
        n = 1
        # 顯示員工資訊
        for emp in emps :
            print(f'\t{n}\t{emp}')
            n += 1
    elif user_choose == '2':
        # 添加員工
        # 擷取要添加員工的資訊,姓名、年齡、性别、住址
        emp_name = input('請輸入員工姓名:')
        emp_age = input('請輸入員工年齡:')
        emp_gender = input('請輸入員工性别:')
        emp_address = input('請輸入員工住址:')
        # 建立員工資訊
        emp = f'{emp_name}\t{emp_age}\t{emp_gender}\t{emp_address}'
        # 顯示一個提示資訊
        print('以下員工将被添加到系統中:')
        print('-'*62)
        print('姓名\t年齡\t性别\t住址')
        print(emp)
        print('-'*62)
        user_confirm = input('是否确認該操作[Y/N]:')
        # 判斷
        if user_confirm == 'y' or user_confirm == 'yes' :
            emps.append(emp)    
        else :
            print('添加已取消!')
    elif user_choose == '3' :
        # 删除員工,根據員工的序号删除員工
        # 擷取要删除員工的序号
        del_num = int(input('請輸入要删除員工的序号:'))
        # 判斷序号是否有效
        if 0 < del_num <= len(emps):
            # 輸入合法,根據序号來擷取索引
            del_i = del_num - 1
            # 顯示提示
            print('以下員工将被删除:')
            print('-'*62)
            print('\t序号\t姓名\t年齡\t性别\t住址')
            print(f'\t{del_num}\t{emps[del_i]}')
            print('-'*62)
            user_confirm = input('該操作不可恢複,是否确認[Y/N]:')
            # 删除元素
            if user_confirm == 'y' or user_confirm == 'yes':
                emps.pop(del_i)
                # 提示資訊
                print('員工已經被删除!')
            else :
                # 操作取消
                print('操作已經取消!')
        else :
            print('你的輸入有誤!')
    elif user_choose == '4' :
        # 退出
        input('歡迎使用! 再見 ! 點選回車退出!')
        break
    else :
        print('你的輸入有誤,請重新選擇!')
    # 列印分割線
    print('-'*62)

           

效果圖如下所示:

Python指令行版本的員工管理系統
Python指令行版本的員工管理系統
Python指令行版本的員工管理系統