forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
To Do List App
50 lines (42 loc) · 1.38 KB
/
To Do List App
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
class ToDoList:
def __init__(self):
self.tasks = []
def add_task(self, task):
self.tasks.append(task)
print(f"Task '{task}' added to the list.")
def remove_task(self, task):
if task in self.tasks:
self.tasks.remove(task)
print(f"Task '{task}' removed from the list.")
else:
print(f"Task '{task}' not found in the list.")
def view_tasks(self):
if not self.tasks:
print("The to-do list is empty.")
else:
print("To-do list:")
for idx, task in enumerate(self.tasks, start=1):
print(f"{idx}. {task}")
def main():
to_do_list = ToDoList()
while True:
print("\n1. Add Task")
print("\n2. Remove Task")
print("\n3. View Tasks")
print("\n4. Quit")
choice = input("Enter your choice (1/2/3/4): ")
if choice == '1':
task = input("Enter the task: ")
to_do_list.add_task(task)
elif choice == '2':
task = input("Enter the task to remove: ")
to_do_list.remove_task(task)
elif choice == '3':
to_do_list.view_tasks()
elif choice == '4':
print("Exiting the to-do list app.")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()