-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo_list.py
46 lines (39 loc) · 1.18 KB
/
todo_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
44
45
46
tasks = []
def add_task(task):
tasks.append(task)
print(f"Task '{task}' added.")
def view_tasks():
if not tasks:
print("No tasks.")
else:
print("Tasks:")
for index, task in enumerate(tasks, start=1):
print(f"{index}. {task}")
def delete_task(index):
if 1 <= index <= len(tasks):
deleted_task = tasks.pop(index - 1)
print(f"Deleted task: '{deleted_task}'")
else:
print("Invalid index.")
def todo_list():
while True:
print("\nTODO List Application")
print("1. Add Task")
print("2. View Tasks")
print("3. Delete Task")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == '1':
task = input("Enter task: ")
add_task(task)
elif choice == '2':
view_tasks()
elif choice == '3':
index = int(input("Enter index of task to delete: "))
delete_task(index)
elif choice == '4':
print("Exiting program.")
break
else:
print("Invalid input. Please try again.")
todo_list()