staffs = []
class Staff:
def __init__(self, sid, name, gender, birthdate):
self.sid = sid
self.name = name
self.gender = gender
self.birthdate = birthdate
def __str__(self):
return f'{self.sid}\t{self.name}\t{self.gender}\t{self.birthdate}'
def show_menu():
menu = '''***员工信息管理系统***
1. 录入信息 2. 打印信息
3. 查询信息 4. 修改信息
5. 删除信息 0. 退出系统'''
print(menu)
def add():
print('**录入信息**')
sid = input('员工ID:')
name = input('姓名:')
gender = input('性别:')
birthdate = input('出生日期:')
staff = Staff(sid, name, gender, birthdate)
staffs.append(staff)
print('数据已保存!')
choice = input('继续录入吗(Y/N)?')
if choice.upper() == 'Y':
add()
elif choice.upper() == 'N':
return
def display():
print('**打印信息**')
for staff in staffs:
print(staff)
print('请按回车键继续. . .', end='')
input()
def query():
sid = input('请输入要查询的员工ID:')
for staff in staffs:
if sid == staff.sid:
print('已经找到,该员工信息如下:')
print(staff)
break
else:
print('查无此人')
print('请按回车键继续. . .', end='')
input()
def modify():
print('**修改信息**')
sid = input('请输入要修改的员工ID:')
for staff in staffs:
if sid == staff.sid:
print('原有信息:', staff)
if name == input('姓名:'):
staff.name = name
if gender == input('性别:'):
staff.gender = gender
if birthdate == input('出生日期:'):
staff.birthdate = birthdate
print('修改之后: ', staff)
break
else:
print('查无此人')
print('请按回车键继续. . .', end='')
input()
def delete():
global staffs
print('**删除信息**')
sid = input('请输入要删除的员工ID:')
for i in range(len(staffs)):
if sid == staffs[i].sid:
del staffs[i]
print('信息删除成功!')
break
else:
print('查无此人')
print('请按回车键继续. . .', end='')
input()
if __name__ == '__main__':
while 1:
show_menu()
choice = int(input('请输入你的选择(0-5):'))
if choice == 1:
add()
elif choice == 2:
display()
elif choice == 3:
query()
elif choice == 4:
modify()
elif choice == 5:
delete()
elif choice == 0:
print('系统已退出,谢谢使用!')
break
else:
print('无效选择!')
python 员工信息管理系统案例
最新推荐文章于 2023-02-25 11:08:00 发布