└── Main /Main: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | TODO_FILE = "todo.json" 5 | 6 | def load_tasks(): 7 | if os.path.exists(TODO_FILE): 8 | with open(TODO_FILE, "r") as file: 9 | return json.load(file) 10 | return [] 11 | 12 | def save_tasks(tasks): 13 | with open(TODO_FILE, "w") as file: 14 | json.dump(tasks, file, indent=4) 15 | 16 | def add_task(task): 17 | tasks = load_tasks() 18 | tasks.append({"task": task, "done": False}) 19 | save_tasks(tasks) 20 | print("Task added!") 21 | 22 | def list_tasks(): 23 | tasks = load_tasks() 24 | for i, t in enumerate(tasks): 25 | status = "[✓]" if t["done"] else "[ ]" 26 | print(f"{i+1}. {status} {t['task']}") 27 | 28 | def complete_task(task_index): 29 | tasks = load_tasks() 30 | if 0 <= task_index < len(tasks): 31 | tasks[task_index]["done"] = True 32 | save_tasks(tasks) 33 | print("Task marked as complete!") 34 | 35 | if __name__ == "__main__": 36 | while True: 37 | action = input("Add (A), List (L), Complete (C), Exit (E): ").strip().upper() 38 | 39 | if action == "A": 40 | task = input("Enter new task: ") 41 | add_task(task) 42 | elif action == "L": 43 | list_tasks() 44 | elif action == "C": 45 | index = int(input("Enter task number to complete: ")) - 1 46 | complete_task(index) 47 | elif action == "E": 48 | break 49 | --------------------------------------------------------------------------------