-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodoList.py
More file actions
79 lines (67 loc) · 1.74 KB
/
Copy pathtodoList.py
File metadata and controls
79 lines (67 loc) · 1.74 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
#todolist
import time
import os
FILENAME = "tasks.txt"
tasks = []
def load_tasks():
if os.path.exists(FILENAME):
with open(FILENAME, "r") as file:
for line in file:
tasks.append(line.strip())
def save_tasks():
with open(FILENAME, "w") as file:
for task in tasks:
file.write(task + "\n")
def show_menu():
print("\nTo-Do List Menu:")
print("1. Show tasks")
print("2. Add task")
print("3. Remove task")
print("4. Exit")
def show_tasks():
if not tasks:
print("Your to-do list is empty.")
else:
print("\nYour Tasks:")
for i, task in enumerate(tasks, start=1):
print(f"{i}. {task}")
time.sleep(2)
def add_task():
task = input("Enter a new task: ")
tasks.append(task)
save_tasks()
print("Task added.")
time.sleep(2)
def remove_task():
show_tasks()
if not tasks:
return
try:
task_num = int(input("Enter the number of the task to remove: "))
if 1 <= task_num <= len(tasks):
removed = tasks.pop(task_num - 1)
save_tasks()
print(f"Removed task: {removed}")
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
time.sleep(2)
def main():
load_tasks()
while True:
show_menu()
choice = input("Choose a option (1-4): ")
if choice == '1':
show_tasks()
elif choice == '2':
add_task()
elif choice == '3':
remove_task()
elif choice == '4':
print("Goodbye!")
break
else:
print("Invalid option. Please choose 1-4.")
if __name__ == "__main__":
main()