-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path95. Simple To-Do List.py
More file actions
47 lines (42 loc) · 1.21 KB
/
95. Simple To-Do List.py
File metadata and controls
47 lines (42 loc) · 1.21 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
class TodoList:
def __init__(self):
self.tasks = []
def add_task(self, task):
self.tasks.append(task)
print("Task added successfully!")
def remove_task(self, task):
if task in self.tasks:
self.tasks.remove(task)
print("Task removed successfully!")
else:
print("Task not found.")
def view_tasks(self):
if self.tasks:
print("Tasks:")
for task in self.tasks:
print(task)
else:
print("No tasks found.")
def main():
todo_list = TodoList()
while True:
print("\n1. Add Task")
print("2. Remove Task")
print("3. View Tasks")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == '1':
task = input("Enter task: ")
todo_list.add_task(task)
elif choice == '2':
task = input("Enter task to remove: ")
todo_list.remove_task(task)
elif choice == '3':
todo_list.view_tasks()
elif choice == '4':
print("Exiting...")
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()