帮我写一个考勤管理系统后台代码
时间: 2023-07-10 21:18:14 浏览: 84
好的,考勤管理系统后台代码如下(仅供参考):
```python
# -*- coding: utf-8 -*-
import datetime
# 定义一个员工类
class Employee:
def __init__(self, name, id):
self.name = name
self.id = id
self.attendances = []
# 打印员工信息
def print_info(self):
print("Name: {}, ID: {}".format(self.name, self.id))
# 员工打卡
def clock_in(self):
now = datetime.datetime.now()
self.attendances.append(now)
# 获取员工出勤天数
def get_attendance_days(self):
days = 0
for i in range(len(self.attendances)):
if i+1 < len(self.attendances) and (self.attendances[i+1]-self.attendances[i]).days == 1:
days += 1
return days
# 定义一个考勤管理类
class AttendanceManager:
def __init__(self):
self.employees = []
# 添加员工
def add_employee(self, employee):
self.employees.append(employee)
# 删除员工
def remove_employee(self, employee):
self.employees.remove(employee)
# 获取所有员工的出勤天数
def get_all_attendance_days(self):
result = {}
for employee in self.employees:
result[employee.name] = employee.get_attendance_days()
return result
# 测试代码
if __name__ == "__main__":
# 初始化考勤管理系统
manager = AttendanceManager()
# 添加员工
employee1 = Employee("Bob", "001")
employee2 = Employee("Alice", "002")
manager.add_employee(employee1)
manager.add_employee(employee2)
# 员工打卡
employee1.clock_in()
employee1.clock_in()
employee1.clock_in()
employee2.clock_in()
employee2.clock_in()
# 输出所有员工的出勤天数
attendance_days = manager.get_all_attendance_days()
for name, days in attendance_days.items():
print("Name: {}, Attendance days: {}".format(name, days))
```
以上代码实现了一个简单的考勤管理系统,包含了员工打卡、获取出勤天数等功能。可以根据自己的需求进行修改和扩展。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)