forked from CSEdgeOfficial/Python-Programming-Internship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoList
More file actions
51 lines (43 loc) · 1.4 KB
/
TodoList
File metadata and controls
51 lines (43 loc) · 1.4 KB
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 '{task}' added to the to-do list.")
def remove_task(self, task):
if task in self.tasks:
self.tasks.remove(task)
print(f"Task '{task}' removed from the to-do list.")
else:
print(f"Task '{task}' not found in the to-do list.")
def show_tasks(self):
if self.tasks:
print("Your to-do list:")
for i, task in enumerate(self.tasks, start=1):
print(f"{i}. {task}")
else:
print("Your to-do list is empty.")
def main():
todo_list = TodoList()
while True:
print("\nWhat would you like to do?")
print("1. Add task")
print("2. Remove task")
print("3. Show tasks")
print("4. 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.show_tasks()
elif choice == '4':
print("Exiting program...")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()