【发布时间】:2022-11-14 10:05:27
【问题描述】:
我正在尝试在截止日期之前显示作业。 我正在尝试根据截止日期对作业进行排序,然后按该顺序打印作业。
class Assignment:
def __init__(self):
#Don't change.
self.assignments = []
def add(self, due_date, course):
# Add the due_date, course as list to the assignments list.
# Nothing is returned.
def remove(self, due_date, course):
# Create a list with due_date and course.
# If the [due_date, course] list is in assignments list, then remove it from the list.
# Otherwise, do nothing.
# Nothing is returned.
def display_assignment(self):
print("Display assignments by order they are entered.")
# Display each assignment by the order they entered, line by line.
def display_assignment_by_due_date(self):
print("Display assignments by due dates.")
# Display each assignment ordered by due date, line by line.
#Do not change.
if __name__ == "__main__":
assignment = Assignment()
assignment.add("10/21/2020", "COMP120")
assignment.add("10/30/2020", "MATH220")
assignment.add("10/07/2020", "ITEC136")
assignment.add("10/14/2020", "ENGL120")
assignment.display_assignment()
assignment.display_assignment_by_due_date()
assignment.remove("10/14/2020", "ENGL120")
assignment.display_assignment()
assignment.display_assignment_by_due_date()
【问题讨论】:
-
你能发布你已经尝试过的代码吗?
-
你的 display_assignment() 代码是什么?我建议添加一个包含作业列表的新类,以便更轻松地正确使用它们。
标签: python