-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDo_Notes.py
More file actions
107 lines (87 loc) · 2.77 KB
/
ToDo_Notes.py
File metadata and controls
107 lines (87 loc) · 2.77 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
102
103
104
105
106
107
import os
class Todo:
def __init__(self, filename="tasks.txt"):
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:
self.tasks = [line.strip() for line in file if line.strip()]
def save_tasks(self):
with open(self.filename, "w") as file:
for task in self.tasks:
file.write(task + "\n")
def add_task(self, task):
if task.strip() == "":
print("Task cannot be empty!")
return
if task in self.tasks:
print("Task already exists!")
return
self.tasks.append(task)
self.save_tasks()
print("Task added successfully!")
def view_tasks(self):
if not self.tasks:
print("No tasks found!")
else:
print("\nYour Tasks:")
for i, task in enumerate(self.tasks, 1):
print(f"{i}. {task}")
def delete_task(self, index):
if 0 <= index < len(self.tasks):
removed = self.tasks.pop(index)
self.save_tasks()
print(f"Task '{removed}' deleted!")
else:
print("Invalid task number!")
def mark_complete(self, index):
if 0 <= index < len(self.tasks):
if "[DONE]" not in self.tasks[index]:
self.tasks[index] += " [DONE]"
self.save_tasks()
print("Task marked as completed!")
else:
print("Task already completed!")
else:
print("Invalid task number!")
todo = Todo()
while True:
print("\n--- To-Do Notes Builder ---")
print("1. Add Task")
print("2. View Tasks")
print("3. Delete Task")
print("4. Mark Task Complete")
print("5. Exit")
choice = input("Enter choice: ")
if not choice.isdigit():
print("Please enter a valid number!")
continue
choice = int(choice)
if choice == 1:
task = input("Enter task: ")
todo.add_task(task)
elif choice == 2:
todo.view_tasks()
elif choice == 3:
todo.view_tasks()
if todo.tasks:
num = input("Enter task number to delete: ")
if num.isdigit():
todo.delete_task(int(num) - 1)
else:
print("Invalid input!")
elif choice == 4:
todo.view_tasks()
if todo.tasks:
num = input("Enter task number to mark complete: ")
if num.isdigit():
todo.mark_complete(int(num) - 1)
else:
print("Invalid input!")
elif choice == 5:
print("Exiting program.....")
break
else:
print("Invalid choice!")