如何在待办事项列表中添加时间和状态功能

2024-10-02 06:26:20 发布

您现在位置:Python中文网/ 问答频道 /正文

本周我开始认真学习python(这是我计划学习的第一门语言),今天我写了这个待办事项列表脚本。我实现了add、remove和view特性,但是现在我希望能够添加到期时间,并标记是否完成。我该怎么做?提前谢谢!代码如下

list = []

def add():
    global itemadd
    itemadd = input("What would you like to add?")
    list.append(itemadd)
    print("You've added " + itemadd + " to your to-do list. Here is what your list currently looks like:")
    print(list)

def remove():
    print(list)
    global itemremove
    itemremove = input("What would you like to remove?")
    if itemremove in list:
      list.remove(itemremove)
    else:
      while itemremove not in list:
        print("This item is not on your to-do list. Did you spell it correctly?")
        itemremove = input("Try again:")
    print("You have removed " + itemremove + " from your to-do list. Here is what your list currently looks like:")
    print(list)


def prompt():
    ask = input("What would you like to do? (add an item (add), view list (view), remove an item (remove))")

    if ask == "add":
        add()
    elif ask == "view":
        print("Here is your to-do list:")
        print(list)
    elif ask == "remove":
        remove()

stop = False

while not stop:
  prompt()

Tags: toyouviewaddinputyourisdo
1条回答
网友
1楼 · 发布于 2024-10-02 06:26:20

您可以创建一个类来记录需要做的每件事,并创建另一个类来保存要做的事:

class ThingToDo:
    def __init__(self, thing, date, status):
        self.thing = thing
        self.date = date
        self.status = status
    ...

class ListOfThingsToDo:
    def __init__(self):
        self.things_to_do = []
        ...

然后实现add_thingremove_thingupdate_statusarchive_thingreprogram_thing等方法

相关问题 更多 >

    热门问题