forked from Adityaranjanpatra/Btecky2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TO DO LIST IN PYTHON
46 lines (40 loc) · 1.21 KB
/
TO DO LIST IN PYTHON
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 list_tasks():
if tasks:
print("To-Do List:")
for index, task in enumerate(tasks, start=1):
print(f"{index}. {task}")
else:
print("Your to-do list is empty!")
def remove_task(task_index):
if 1 <= task_index <= len(tasks):
removed_task = tasks.pop(task_index - 1)
print(f"Task '{removed_task}' removed!")
else:
print("Invalid task index. Try again.")
def main():
while True:
print("\nOptions:")
print("1. Add a task")
print("2. List tasks")
print("3. Remove a task")
print("4. Quit")
choice = input("Enter your choice (1/2/3/4): ")
if choice == "1":
task = input("Enter the task: ")
add_task(task)
elif choice == "2":
list_tasks()
elif choice == "3":
task_index = int(input("Enter the task index to remove: "))
remove_task(task_index)
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid choice. Please select a valid option.")
if __name__ == "__main__":
main()