2024年1月26日发(作者:)
python项目案例代码
以下是一个简单的Python项目案例代码,用于实现一个简易的待办事项管理系统:
python.
class TodoItem:
def __init__(self, task, priority):
= task.
ty = priority.
def __str__(self):
return f"{} Priority: {ty}"
class TodoList:
def __init__(self):
_items = []
def add_item(self, item):
_(item)。
def remove_item(self, item):
if item in _items:
_(item)。
def get_items(self):
return _items.
def get_priority_items(self, priority):
priority_items = []
for item in _items:
if ty == priority:
priority_(item)。
return priority_items.
def main():
todo_list = TodoList()。
while True:
print("n--Todo List Menu ---")。
print("1. Add item")。
print("2. Remove item")。
print("3. View all items")。
print("4. View items by priority")。
print("5. Exit")。
choice = input("Enter your choice (1-5): ")。
if choice == "1":
task = input("Enter the task: ")
priority = input("Enter the priority (High,
Medium, Low): ")
item = TodoItem(task, priority)
todo__item(item)
print("Item added successfully!")
elif choice == "2":
task = input("Enter the task to remove: ")。
。
。
。
。
。
items = todo__items()。
for item in items:
if == task:
todo__item(item)。
print("Item removed successfully!")。
break.
else:
print("Item not found!")。
elif choice == "3":
items = todo__items()。
if not items:
print("No items found!")。
else:
print("--All Items ---")。
for item in items:
print(item)。
elif choice == "4":
priority = input("Enter the priority (High,
Medium, Low): ")。
priority_items =
todo__priority_items(priority)。
if not priority_items:
print("No items found with the given
priority!")。
else:
print(f"--{priority} Priority Items ---")。
for item in priority_items:
print(item)。
elif choice == "5":
print("Thank you for using the Todo List!")。
break.
else:
print("Invalid choice! Please enter a
number from 1 to 5.")。
if __name__ == "__main__":
main()。
这个案例代码实现了一个简单的待办事项管理系统,用户可以添加、删除、查看所有事项以及按照优先级查看事项。用户可以通过命令行菜单选择操作。每个待办事项由任务和优先级组成,优先级分为高、中、低三个级别。用户可以根据自己的需求进行操作。
本文发布于:2024-01-26 08:59:23,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/1706230763820.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |