删除员工,添加员工 员工管理系统 pta python

删除员工,添加员工 员工管理系统 pta python


对原本的题目稍作修改,加上了本地添加历史和删除历史的查询
以下是代码
下面展示一些 内联代码片

#----员工管理系统---------
print("*"*20,"欢迎使用员工信息系统","*"*20)
emps = ['\t小李\t18\t女\t花果山']#员工信息以字符串形式存储在列表中
history_del = []
history_append =[]
while True:
      print(" 请选择你的操作 ")
      print('\t1."查询员工')
      print('\t2.添加员工')
      print('\t3.删除员工')
      print('\t4.退出系统')
      print('\t5.查看操作历史集合')
      user_choose = input('请选择[1-4]:')
      print("-" * 42)
      if user_choose == '1':
            print("\t序号    \t姓名\t年龄\t性别\t住址")
            n = 1
            for i in emps:
                  print(f'\t{n}\t{i}')
                  n += 1
            pass
      elif user_choose == '2':
            print("\t序号    \t姓名\t年龄\t性别\t住址")
            print("输入格式为 '\t小李\t18\t女\t花果山' ")
            emps_new = input("\t\t\t")
            emps.append(emps_new)
            history_append.append(emps_new)
      elif user_choose == '3':
            pass
      #获取删除员工的序号
            del_number = int(input('请输入要删除的员工的序号'))
            #判断输入值是否有效
            if del_number <= len(emps):
                  del_index = del_number - 1
                  print("该员工将被删除")
                  print("*"*42)
                  print("\t序号    \t姓名\t年龄\t性别\t住址")
                  print(f'\t{del_number}\t{emps[del_index]}')
                  print("*"*42)
                  user_confirm = input("是否确认该操作 [Y/N]")
                  print('该操作不可恢复')
                  if user_confirm == 'Y' or user_confirm == 'yes':
                        history_del.append(emps[del_index])
                        emps.pop(del_index)
                  else:
                        print('操作取消')


            else:
                  print("输入有误请重新操作")
      elif user_choose == '4':
            print("-" * 42)
            input('感谢使用,点击回车退出')
            break

            #打印分割线
      elif user_choose == "5":
            print("调用历史记录:[最近新添记录],[最近删除记录]")
            print("1.最近新添   2.最近删除")
            user_choose02 = input("你的选择是 ")
            if user_choose02 == '1':
                  print("\t序号    \t姓名\t年龄\t性别\t住址")
                  for j in history_append:
                        print(f'\t{n}\t{j}')
            elif user_choose02 == '2':
                  print("\t序号    \t姓名\t年龄\t性别\t住址")
                  for k in history_del:
                        print(f'\t{n}\t{k}')
            else:
                  print("输入错误,请重新操作")
      else:
            print("请重新操作")
      print("-"*42)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值