-
Notifications
You must be signed in to change notification settings - Fork 0
/
to do list.py
43 lines (36 loc) · 1.16 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
class ToDoList:
def __init__(self):
self.tasks = []
def add_task(self, task):
self.tasks.append(task)
def remove_task(self, task):
if task in self.tasks:
self.tasks.remove(task)
else:
print("Task not found in the list")
def display_tasks(self):
if len(self.tasks) == 0:
print("No tasks in the list")
else:
print("Tasks:")
for i, task in enumerate(self.tasks, 1):
print(f"{i}. {task}")
def main():
todo_list = ToDoList()
while True:
print("\n1. Add Task\n2. Remove Task\n3. Display Tasks\n4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
task = input("Enter the task: ")
todo_list.add_task(task)
elif choice == "2":
task = input("Enter the task to remove: ")
todo_list.remove_task(task)
elif choice == "3":
todo_list.display_tasks()
elif choice == "4":
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()