-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathto-do
More file actions
67 lines (58 loc) · 1.72 KB
/
to-do
File metadata and controls
67 lines (58 loc) · 1.72 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
import os
TASKS_FILE = "tasks.txt"
def load_tasks():
if not os.path.exists(TASKS_FILE):
return []
with open(TASKS_FILE, "r") as file:
return [line.strip() for line in file.readlines()]
def save_tasks(tasks):
with open(TASKS_FILE, "w") as file:
for task in tasks:
file.write(task + "\n")
def show_tasks(tasks):
if not tasks:
print("✅ No tasks in your to-do list.")
else:
print("\n📝 Your To-Do List:")
for i, task in enumerate(tasks, 1):
print(f"{i}. {task}")
print()
def add_task(tasks):
task = input("Enter a new task: ")
tasks.append(task)
save_tasks(tasks)
print("✔️ Task added.\n")
def delete_task(tasks):
show_tasks(tasks)
try:
index = int(input("Enter the number of the task to delete: "))
if 1 <= index <= len(tasks):
removed = tasks.pop(index - 1)
save_tasks(tasks)
print(f"🗑️ Removed: {removed}\n")
else:
print("❌ Invalid task number.\n")
except ValueError:
print("❌ Please enter a valid number.\n")
def main():
tasks = load_tasks()
while True:
print("📌 To-Do List Options:")
print("1. View tasks")
print("2. Add task")
print("3. Delete task")
print("4. Exit")
choice = input("Choose an option (1-4): ")
if choice == "1":
show_tasks(tasks)
elif choice == "2":
add_task(tasks)
elif choice == "3":
delete_task(tasks)
elif choice == "4":
print("👋 Goodbye!")
break
else:
print("❌ Invalid option. Try again.\n")
if __name__ == "__main__":
main()