forked from DhanushNehru/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_do_list
51 lines (43 loc) · 1.45 KB
/
to_do_list
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
class ToDoList:
def __init__(self):
self.tasks = []
def add_task(self, task):
self.tasks.append(task)
print(f'Task added: "{task}"')
def view_tasks(self):
if not self.tasks:
print("No tasks in the list.")
else:
print("To-Do List:")
for index, task in enumerate(self.tasks, start=1):
print(f"{index}. {task}")
def remove_task(self, task_number):
try:
removed_task = self.tasks.pop(task_number - 1)
print(f'Task removed: "{removed_task}"')
except IndexError:
print("Invalid task number.")
def main():
todo_list = ToDoList()
while True:
print("\nOptions:")
print("1. Add Task")
print("2. View Tasks")
print("3. Remove Task")
print("4. Exit")
choice = input("Choose an option (1-4): ")
if choice == '1':
task = input("Enter the task: ")
todo_list.add_task(task)
elif choice == '2':
todo_list.view_tasks()
elif choice == '3':
task_number = int(input("Enter the task number to remove: "))
todo_list.remove_task(task_number)
elif choice == '4':
print("Exiting the to-do list application.")
break
else:
print("Invalid option. Please choose again.")
if __name__ == "__main__":
main()