Untitled

 avatar
unknown
plain_text
a month ago
1.4 kB
3
Indexable
todo_list = []

def display_menu():
    print("\n-----To Do List-----")
    print("1. View tasks")
    print("2. Add task")
    print("3. Delete task")
    print("4. Exit")

def view_tasks():
    if not todo_list:
        print("No tasks to show!")
    else:
        print("Your To-Do list:")
        for i, task in enumerate(todo_list, 1):
            print(f"{i}. {task}")

def add_task():
    task = input("Enter the task to add: ")
    todo_list.append(task)
    print("Task added!")

def delete_task():
    if not todo_list:
        print("\nNo tasks to delete")
    else:
        view_tasks()
        try:
            task_number = int(input("Enter the task number to delete: "))
            if 1 <= task_number <= len(todo_list):
                removed_task = todo_list.pop(task_number - 1)
                print(f"Task '{removed_task}' deleted!")
            else:
                print("Invalid task number.")
    except ValueError:
            print("Invalid input. Please enter a number.")

while True:
    display_menu()
    choice = input("Enter your choice: ")

    if choice == '1':
        view_tasks()
    elif choice == '2':
        add_task()
    elif choice == '3':
        delete_task()
    elif choice == '4':
        print("Exiting...")
        break
    else:
        print("Invalid choice. Please try again.")
Leave a Comment