Simple To-Do List Application in Python: Manage Tasks Easily

Tips on How to Use the To-Do List Code
Add Task:

Choose option 1 from the menu to add a new task.
Enter a description of the task when prompted. The task will be added to the list with a status of “Pending.”
Mark Task Complete:

Choose option 2 to mark a task as complete.
First, view all tasks to see the task numbers.
Enter the number corresponding to the task you want to mark as complete. The status of the task will change to “Completed.”
View All Tasks:

Choose option 3 to view all tasks.
This will display a list of all tasks with their statuses (Pending or Completed).
Exit:

Choose option 4 to exit the application.
How to Publish This Code
Hosting:

For a web-based application, you would need to use a web framework like Flask or Django in Python. This code is a console-based application, so it needs to be adapted for web use.
Python Web Application:

If you want to deploy a Python-based web application, consider using Flask. You would need to convert this code into routes and templates for a web server.
Documentation:

Provide clear instructions on how to run the script if you’re sharing it as a console application. Include information on required Python version and dependencies if any.

Python Code

# Simple To-Do List Application

def display_menu():
    print("\nTo-Do List Menu:")
    print("1. Add Task")
    print("2. Mark Task Complete")
    print("3. View All Tasks")
    print("4. Exit")

def add_task(task_list):
    task = input("Enter the task: ")
    task_list.append({"task": task, "completed": False})
    print(f"Task '{task}' added.")

def mark_task_complete(task_list):
    view_tasks(task_list)
    task_index = int(input("Enter the task number to mark as complete: ")) - 1
    if 0 <= task_index < len(task_list):
        task_list[task_index]["completed"] = True
        print(f"Task '{task_list[task_index]['task']}' marked as complete.")
    else:
        print("Invalid task number.")

def view_tasks(task_list):
    if not task_list:
        print("No tasks available.")
        return
    print("\nTasks List:")
    for index, task in enumerate(task_list, start=1):
        status = "Completed" if task["completed"] else "Pending"
        print(f"{index}. {task['task']} - {status}")

def main():
    task_list = []
    while True:
        display_menu()
        choice = input("Enter your choice: ")
        if choice == '1':
            add_task(task_list)
        elif choice == '2':
            mark_task_complete(task_list)
        elif choice == '3':
            view_tasks(task_list)
        elif choice == '4':
            print("Exiting the application.")
            break
        else:
            print("Invalid choice. Please try again.")

if __name__ == "__main__":
    main()

 

Compiled Code With Results

Wikipedia 


 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Resize text
Scroll to Top