用python生成一个员工工资管理系统
时间: 2023-07-18 12:14:17 浏览: 180
python 实现员工工资信息管理系统
好的,我可以帮你讲解一下如何用 Python 来生成一个简单的员工工资管理系统。以下是一个基本的框架,你可以在此基础上进行修改和完善。
1. 定义员工类
首先,我们需要定义一个员工类来存储员工的信息,比如姓名、工号、薪水等。
```python
class Employee:
def __init__(self, name, id, salary):
self.name = name
self.id = id
self.salary = salary
```
2. 添加员工
接下来,我们需要实现添加员工的功能。我们可以使用一个列表来存储所有的员工信息。
```python
employees = []
def add_employee():
name = input("请输入员工姓名:")
id = input("请输入员工工号:")
salary = input("请输入员工薪水:")
employee = Employee(name, id, salary)
employees.append(employee)
print("添加成功!")
```
3. 查找员工
我们可以通过员工的工号来查找员工信息。
```python
def find_employee():
id = input("请输入员工工号:")
for employee in employees:
if employee.id == id:
print("姓名:", employee.name)
print("工号:", employee.id)
print("薪水:", employee.salary)
return
print("未找到该员工!")
```
4. 修改员工信息
我们可以通过员工的工号来修改员工的薪水。
```python
def update_employee():
id = input("请输入员工工号:")
for employee in employees:
if employee.id == id:
salary = input("请输入员工新的薪水:")
employee.salary = salary
print("修改成功!")
return
print("未找到该员工!")
```
5. 删除员工
我们可以通过员工的工号来删除员工的信息。
```python
def delete_employee():
id = input("请输入员工工号:")
for employee in employees:
if employee.id == id:
employees.remove(employee)
print("删除成功!")
return
print("未找到该员工!")
```
6. 显示所有员工
最后,我们可以实现显示所有员工信息的功能。
```python
def show_employees():
for employee in employees:
print("姓名:", employee.name)
print("工号:", employee.id)
print("薪水:", employee.salary)
```
完整代码如下:
```python
class Employee:
def __init__(self, name, id, salary):
self.name = name
self.id = id
self.salary = salary
employees = []
def add_employee():
name = input("请输入员工姓名:")
id = input("请输入员工工号:")
salary = input("请输入员工薪水:")
employee = Employee(name, id, salary)
employees.append(employee)
print("添加成功!")
def find_employee():
id = input("请输入员工工号:")
for employee in employees:
if employee.id == id:
print("姓名:", employee.name)
print("工号:", employee.id)
print("薪水:", employee.salary)
return
print("未找到该员工!")
def update_employee():
id = input("请输入员工工号:")
for employee in employees:
if employee.id == id:
salary = input("请输入员工新的薪水:")
employee.salary = salary
print("修改成功!")
return
print("未找到该员工!")
def delete_employee():
id = input("请输入员工工号:")
for employee in employees:
if employee.id == id:
employees.remove(employee)
print("删除成功!")
return
print("未找到该员工!")
def show_employees():
for employee in employees:
print("姓名:", employee.name)
print("工号:", employee.id)
print("薪水:", employee.salary)
while True:
print("1. 添加员工")
print("2. 查找员工")
print("3. 修改员工信息")
print("4. 删除员工")
print("5. 显示所有员工")
print("6. 退出程序")
choice = input("请输入您的选择:")
if choice == '1':
add_employee()
elif choice == '2':
find_employee()
elif choice == '3':
update_employee()
elif choice == '4':
delete_employee()
elif choice == '5':
show_employees()
elif choice == '6':
break
else:
print("请输入正确的选项!")
```
希望这个简单的员工工资管理系统对你有所帮助!
阅读全文