Skip to main content
  1. Blog/

How programming can help reduce mental load 🦾

·325 words·2 mins

Welcome to aichat 0.17.0

Type “.help” for additional help.

alm> I need help! My mental load is too much. Write some python code to help me get organized! Sure, here is a simple Python script that can help you manage your tasks. It allows you to add, view, and remove tasks from a to-do list.

import json
import os

FILENAME = 'todo_list.json'

def load_tasks():
    if os.path.exists(FILENAME):
        with open(FILENAME, 'r') as file:
            return json.load(file)
    return []

def save_tasks(tasks):
    with open(FILENAME, 'w') as file:
        json.dump(tasks, file, indent=4)

def add_task(task):
    tasks = load_tasks()
    tasks.append({"task": task, "completed": False})
    print(f'Task "{task}" added!')

def view_tasks():
    tasks = load_tasks()
    if not tasks:
        print("No tasks available.")
        for i, item in enumerate(tasks):
            status = "Done" if item["completed"] else "Not Done"
            print(f"{i + 1}. {item['task']} - {status}")

def remove_task(task_number):
    tasks = load_tasks()
    if 0 < task_number <= len(tasks):
        removed = tasks.pop(task_number - 1)
        print(f'Task "{removed["task"]}" removed!')
        print("Invalid task number.")

def mark_task_as_done(task_number):
    tasks = load_tasks()
    if 0 < task_number <= len(tasks):
        tasks[task_number - 1]["completed"] = True
        print(f'Task "{tasks[task_number - 1]["task"]}" marked as done!')
        print("Invalid task number.")

def main():
    while True:
        print("\n1. Add Task\n2. View Tasks\n3. Remove Task\n4. Mark Task as Done\n5. Exit")
        choice = input("Enter your choice: ")
        if choice == '1':
            task = input("Enter the task: ")
        elif choice == '2':
        elif choice == '3':
            task_number = int(input("Enter task number to remove: "))
        elif choice == '4':
            task_number = int(input("Enter task number to mark as done: "))
        elif choice == '5':
            print("Invalid choice! Please try again.")

if __name__ == "__main__":

This script uses a simple JSON file to store your tasks. You can:

  1. Add a new task.
  2. View all tasks.
  3. Remove a task by its number.
  4. Mark a task as done.
  5. Exit the program.

To run the script, simply execute the Python file in your terminal or command prompt. This should give you a basic task manager to help you get organized.