-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_1_To_Do_List.py
58 lines (48 loc) · 1.66 KB
/
Task_1_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
49
50
51
52
53
54
55
56
57
58
# this is a to_do list written in python
class Task:
def __init__(self, description, completed=False):
self.description = description
self.completed = completed
class TodoList:
def __init__(self):
self.tasks = []
def add_task(self, description):
task = Task(description)
self.tasks.append(task)
def update_task_status(self, task_index, completed=True):
if 0 <= task_index < len(self.tasks):
self.tasks[task_index].completed = completed
else:
print("Invalid task index.")
def display_tasks(self):
if not self.tasks:
print("No tasks in the list.")
else:
print("Task List:")
for i, task in enumerate(self.tasks):
status = "✓" if task.completed else "✗"
print(f"{i + 1}. [{status}] {task.description}")
def main():
todo_list = TodoList()
while True:
print("\nMenu:")
print("1. Add Task")
print("2. Mark Task as Completed")
print("3. Display Tasks")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
description = input("Enter task description: ")
todo_list.add_task(description)
elif choice == "2":
task_index = int(input("Enter task number to mark as completed: ")) - 1
todo_list.update_task_status(task_index)
elif choice == "3":
todo_list.display_tasks()
elif choice == "4":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()