-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo_list.py
More file actions
64 lines (55 loc) · 1.99 KB
/
todo_list.py
File metadata and controls
64 lines (55 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Task:
def __init__(self, description, due_date=None, priority=None):
self.description = description
self.due_date = due_date
self.priority = priority
class ToDoList:
def __init__(self):
self.tasks = []
def add_task(self, task):
self.tasks.append(task)
def view_tasks(self):
if not self.tasks:
print("No tasks yet.")
else:
for i, task in enumerate(self.tasks, 1):
print(f"{i}. {task.description}")
if task.due_date:
print(f" Due Date: {task.due_date}")
if task.priority:
print(f" Priority: {task.priority}")
print()
def delete_task(self, index):
if 1 <= index <= len(self.tasks):
del self.tasks[index - 1]
print("Task deleted successfully.")
else:
print("Invalid task index.")
def main():
todo_list = ToDoList()
while True:
print("\nTo-Do List Menu:")
print("1. Add Task")
print("2. View Tasks")
print("3. Delete Task")
print("4. Quit")
choice = input("Enter your choice: ")
if choice == '1':
description = input("Enter task description: ")
due_date = input("Enter due date (optional): ")
priority = input("Enter priority level (optional): ")
new_task = Task(description, due_date, priority)
todo_list.add_task(new_task)
print("Task added successfully.")
elif choice == '2':
todo_list.view_tasks()
elif choice == '3':
index = int(input("Enter the index of the task to delete: "))
todo_list.delete_task(index)
elif choice == '4':
print("Exiting...")
break
else:
print("Invalid choice. Please enter a number from 1 to 4.")
if __name__ == "__main__":
main()