删除员工,添加员工 员工管理系统 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)