-
Notifications
You must be signed in to change notification settings - Fork 0
/
to-do-list.py
48 lines (44 loc) · 1.72 KB
/
to-do-list.py
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
def todo_list():
tasks = []
while True:
print("\n--- To-Do List ---")
print("1. Add Task")
print("2. View Tasks")
print("3. Mark Task as Complete")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == '1':
task = input("Enter the task: ")
tasks.append({"task": task, "completed": False})
print("Task added successfully!")
elif choice == '2':
if tasks:
print("\nYour Tasks:")
for i, task in enumerate(tasks, 1):
status = "✓" if task["completed"] else " "
print(f"{i}. [{status}] {task['task']}")
else:
print("No tasks in the list.")
elif choice == '3':
if tasks:
print("\nYour Tasks:")
for i, task in enumerate(tasks, 1):
status = "✓" if task["completed"] else " "
print(f"{i}. [{status}] {task['task']}")
try:
task_num = int(input("Enter the task number to mark as complete: ")) - 1
if 0 <= task_num < len(tasks):
tasks[task_num]["completed"] = True
print("Task marked as complete!")
else:
print("Invalid task number.")
except ValueError:
print("Please enter a valid number.")
else:
print("No tasks in the list.")
elif choice == '4':
print("Thank you for using the To-Do List application!")
break
else:
print("Invalid choice. Please try again.")
todo_list()