-
Notifications
You must be signed in to change notification settings - Fork 0
/
task1.py
68 lines (52 loc) · 1.77 KB
/
task1.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
59
60
61
62
63
64
65
class Task:
def __init__(self, description):
self.description = description
self.completed = False
def mark_as_completed(self):
self.completed = True
def __str__(self):
status = "**done**" if self.completed else "!pending!"
return f"[{status}] {self.description}"
class ToDoList:
def __init__(self):
self.tasks = []
def add_task(self, description):
task = Task(description)
self.tasks.append(task)
def mark_task_as_completed(self, index):
if 0 <= index < len(self.tasks):
self.tasks[index].mark_as_completed()
else:
print("Invalid task index.")
def view_tasks(self):
if not self.tasks:
print("No tasks in the to-do list.")
else:
for i, task in enumerate(self.tasks):
print(f"{i + 1}. {task}")
def main():
todo_list = ToDoList()
while True:
print("\n######## TO-DO LIST #########")
print("\n-----------------------------")
print("\n1. Add Task")
print("2. Mark Task as Completed")
print("3. View 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":
index = int(input("Enter the index of the task to mark as completed: ")) - 1
todo_list.mark_task_as_completed(index)
elif choice == "3":
print("\n--- Tasks ---")
todo_list.view_tasks()
elif choice == "4":
print("Exiting...")
break
else:
print("Invalid choice. Please choose again.")
if __name__ == "__main__":
main()