-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTo-Do list.py
More file actions
41 lines (36 loc) · 1.15 KB
/
To-Do list.py
File metadata and controls
41 lines (36 loc) · 1.15 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
class ToDoList:
def __init__(self):
self.tasks = []
def add_task(self, task):
self.tasks.append(task)
def view_tasks(self):
for i, task in enumerate(self.tasks, 1):
print(f"{i}. {task}")
def delete_task(self, task_number):
try:
self.tasks.pop(task_number - 1)
except IndexError:
print("Invalid task number.")
def main():
todo_list = ToDoList()
while True:
print("\nTo-Do List")
print("1. Add task")
print("2. View tasks")
print("3. Delete task")
print("4. Quit")
user_choice = int(input("Enter your choice: "))
if user_choice == 1:
task = input("Enter the task: ")
todo_list.add_task(task)
elif user_choice == 2:
todo_list.view_tasks()
elif user_choice == 3:
task_number = int(input("Enter the task number: "))
todo_list.delete_task(task_number)
elif user_choice == 4:
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()