-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDoList.py
More file actions
101 lines (88 loc) · 3.83 KB
/
Copy pathToDoList.py
File metadata and controls
101 lines (88 loc) · 3.83 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import json
import os
class ToDoList:
def __init__(self, filename='todo_list.json'):
self.filename = filename
self.tasks = self.load_tasks()
def load_tasks(self):
if os.path.exists(self.filename):
with open(self.filename, 'r') as file:
return json.load(file)
return []
def save_tasks(self):
with open(self.filename, 'w') as file:
json.dump(self.tasks, file)
def add_task(self, task, due_date, priority):
self.tasks.append({'task': task, 'due_date': due_date, 'priority': priority, 'completed': False})
self.save_tasks()
print(f'Task "{task}" with due date "{due_date}" and priority "{priority}" added to the list.')
def view_tasks(self):
if not self.tasks:
print("No tasks in the list.")
return
for index, task in enumerate(self.tasks):
status = "✓" if task['completed'] else "✗"
print(f"{index + 1}. [{status}] {task['task']} (Due: {task['due_date']}, Priority: {task['priority']})")
def update_task(self, index, new_task, new_due_date, new_priority):
if 0 <= index < len(self.tasks):
self.tasks[index]['task'] = new_task
self.tasks[index]['due_date'] = new_due_date
self.tasks[index]['priority'] = new_priority
self.save_tasks()
print(f'Task {index + 1} updated to "{new_task}" with due date "{new_due_date}" and priority "{new_priority}".')
else:
print("Invalid task number.")
def delete_task(self, index):
if 0 <= index < len(self.tasks):
removed_task = self.tasks.pop(index)
self.save_tasks()
print(f'Task "{removed_task["task"]}" removed from the list.')
else:
print("Invalid task number.")
def mark_completed(self, index):
if 0 <= index < len(self.tasks):
self.tasks[index]['completed'] = True
self.save_tasks()
print(f'Task {index + 1} marked as completed.')
else:
print("Invalid task number.")
def main():
todo_list = ToDoList()
while True:
print("\nTo-Do List Menu:")
print("1. Add Task")
print("2. View Tasks")
print("3. Update Task")
print("4. Delete Task")
print("5. Mark Task as Completed")
print("6. Exit")
choice = input("Choose an option (1-6): ")
if choice == '1':
task = input("Enter the task: ")
due_date = input("Enter the due date (YYYY-MM-DD): ")
priority = input("Enter the priority (High, Medium, Low): ")
todo_list.add_task(task, due_date, priority)
elif choice == '2':
todo_list.view_tasks()
elif choice == '3':
todo_list.view_tasks()
index = int(input("Enter the task number to update: ")) - 1
new_task = input("Enter the new task: ")
new_due_date = input("Enter the new due date (YYYY-MM-DD): ")
new_priority = input("Enter the new priority (High, Medium, Low): ")
todo_list.update_task(index, new_task, new_due_date, new_priority)
elif choice == '4':
todo_list.view_tasks()
index = int(input("Enter the task number to delete: ")) - 1
todo_list.delete_task(index)
elif choice == '5':
todo_list.view_tasks()
index = int(input("Enter the task number to mark as completed: ")) - 1
todo_list.mark_completed(index)
elif choice == '6':
print("Exiting the To-Do List application.")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()