python作业统计管理系统代码
时间: 2023-08-06 21:13:36 浏览: 102
这里提供一个简单的 Python 作业管理系统代码,你可以根据自己的需求进行修改和完善。
```python
import datetime
class Assignment:
def __init__(self, title, deadline):
self.title = title
self.deadline = deadline
def __str__(self):
return f"{self.title} ({self.deadline.strftime('%Y-%m-%d %H:%M:%S')})"
class AssignmentManager:
def __init__(self):
self.assignments = []
def add_assignment(self, assignment):
self.assignments.append(assignment)
def remove_assignment(self, assignment):
self.assignments.remove(assignment)
def get_assignments(self):
return self.assignments
def get_due_assignments(self):
return [a for a in self.assignments if a.deadline < datetime.datetime.now()]
def get_upcoming_assignments(self, days=7):
return [a for a in self.assignments if a.deadline <= datetime.datetime.now() + datetime.timedelta(days=days)]
```
使用方法:
```python
# 创建一个作业管理器
am = AssignmentManager()
# 添加作业
am.add_assignment(Assignment("作业一", datetime.datetime(2022, 1, 31, 23, 59, 59)))
am.add_assignment(Assignment("作业二", datetime.datetime(2022, 2, 10, 23, 59, 59)))
am.add_assignment(Assignment("作业三", datetime.datetime(2022, 2, 28, 23, 59, 59)))
# 获取所有作业
print("所有作业:")
for a in am.get_assignments():
print(a)
# 获取过期作业
print("过期作业:")
for a in am.get_due_assignments():
print(a)
# 获取接下来一周要完成的作业
print("接下来一周要完成的作业:")
for a in am.get_upcoming_assignments(days=7):
print(a)
# 删除作业
am.remove_assignment(am.assignments[0])
```
阅读全文