Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
120 lines (84 loc) · 2.79 KB
/
Copy pathmain.py
File metadata and controls
120 lines (84 loc) · 2.79 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
108
109
110
111
112
113
114
115
116
117
118
119
120
from todo_manager import TodoManager
def display_menu():
"""Display the main application menu."""
print("\n" + "=" * 40)
print(" TO-DO LIST MANAGER")
print("=" * 40)
print("1. Add Task")
print("2. View Tasks")
print("3. Mark Task as Completed")
print("4. Remove Task")
print("5. Exit")
print("=" * 40)
def add_task(manager):
"""Get task details from the user and add the task."""
title = input("Enter task description: ")
try:
manager.add_task(title)
print("Task added successfully!")
except ValueError as error:
print(f"Error: {error}")
def view_tasks(manager):
"""Display all tasks."""
tasks = manager.view_tasks()
print("\n" + "=" * 40)
print(" YOUR TASKS")
print("=" * 40)
if not tasks:
print("No tasks available.")
else:
for number, task in enumerate(tasks, start=1):
status = "✓" if task.completed else " "
print(f"{number}. [{status}] {task.title}")
print("=" * 40)
def complete_task(manager):
"""Get a task number and mark the task as completed."""
if not manager.tasks:
print("No tasks available to complete.")
return
view_tasks(manager)
try:
task_number = int(input("Enter task number to complete: "))
manager.complete_task(task_number)
print("Task marked as completed!")
except ValueError:
print("Error: Please enter a valid number.")
except IndexError as error:
print(f"Error: {error}")
def remove_task(manager):
"""Get a task number and remove the task."""
if not manager.tasks:
print("No tasks available to remove.")
return
view_tasks(manager)
try:
task_number = int(input("Enter task number to remove: "))
removed_task = manager.remove_task(task_number)
print(f"Task '{removed_task.title}' removed successfully!")
except ValueError:
print("Error: Please enter a valid number.")
except IndexError as error:
print(f"Error: {error}")
def main():
"""Run the To-Do List Manager."""
manager = TodoManager()
print("\nWelcome to the To-Do List Manager!")
while True:
display_menu()
choice = input("Enter your choice (1-5): ").strip()
if choice == "1":
add_task(manager)
elif choice == "2":
view_tasks(manager)
elif choice == "3":
complete_task(manager)
elif choice == "4":
remove_task(manager)
elif choice == "5":
print("\nThank you for using the To-Do List Manager!")
print("Goodbye!")
break
else:
print("Error: Invalid choice. Please enter a number from 1 to 5.")
if __name__ == "__main__":
main()