tasks = [] # list to store tasks
def show_tasks(): if not tasks: print("\nYour to-do list is empty!") else: print("\nYour To-Do List:") for i, task in enumerate(tasks, 1): print(f"{i}. {task}")
def add_task(): task = input("\nEnter a new task: ") tasks.append(task) print("Task added successfully!")
def update_task(): show_tasks() try: task_num = int(input("\nEnter the task number to update: ")) if 1 <= task_num <= len(tasks): new_task = input("Enter the updated task: ") tasks[task_num - 1] = new_task print("Task updated successfully!") else: print("Invalid task number.") except ValueError: print("Please enter a valid number.")
def delete_task(): show_tasks() try: task_num = int(input("\nEnter the task number to delete: ")) if 1 <= task_num <= len(tasks): removed = tasks.pop(task_num - 1) print(f"Task '{removed}' deleted successfully!") else: print("Invalid task number.") except ValueError: print("Please enter a valid number.")
def main(): while True: print("\n--- TO-DO LIST MENU ---") print("1. Show Tasks") print("2. Add Task") print("3. Update Task") print("4. Delete Task") print("5. Exit")
choice = input("Choose an option (1-5): ")
if choice == "1":
show_tasks()
elif choice == "2":
add_task()
elif choice == "3":
update_task()
elif choice == "4":
delete_task()
elif choice == "5":
print("Goodbye! 👋")
break
else:
print("Invalid choice. Please try again.")
main()