-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathto-do.py
47 lines (41 loc) · 1.28 KB
/
to-do.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
47
# Initialize an empty to-do list
todo_list = []
# Function to add a task to the to-do list
def add_task(task):
todo_list.append(task)
print(f"Task '{task}' added to the to-do list.")
# Function to view the to-do list
def view_tasks():
if todo_list:
print("To-Do List:")
for i, task in enumerate(todo_list, start=1):
print(f"{i}. {task}")
else:
print("To-Do List is empty.")
# Function to remove a task from the to-do list
def remove_task(task_index):
if task_index >= 1 and task_index <= len(todo_list):
removed_task = todo_list.pop(task_index - 1)
print(f"Task '{removed_task}' removed from the to-do list.")
else:
print("Invalid task index.")
# Main program loop
while True:
print("\nOptions:")
print("1. Add Task")
print("2. View Tasks")
print("3. Remove Task")
print("4. Quit")
choice = input("Enter your choice: ")
if choice == "1":
task = input("Enter the task: ")
add_task(task)
elif choice == "2":
view_tasks()
elif choice == "3":
task_index = int(input("Enter the task index to remove: "))
remove_task(task_index)
elif choice == "4":
break
else:
print("Invalid choice. Please select a valid option.")