Created
January 17, 2026 04:35
-
-
Save yogesh112211/d2be999a01b85c89b31e1fb3aa3dee73 to your computer and use it in GitHub Desktop.
python3 ' Simple To-Do List Manager '
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import json | |
| TASKS_FILE = "tasks.json" | |
| def load_tasks(): | |
| """Load tasks from file if it exists""" | |
| if os.path.exists(TASKS_FILE): | |
| try: | |
| with open(TASKS_FILE, 'r') as f: | |
| return json.load(f) | |
| except: | |
| return [] | |
| return [] | |
| def save_tasks(tasks): | |
| """Save tasks to file""" | |
| with open(TASKS_FILE, 'w') as f: | |
| json.dump(tasks, f, indent=2) | |
| def show_tasks(tasks): | |
| """Display all tasks""" | |
| if not tasks: | |
| print("No tasks yet! Add some using option 1 ") | |
| return | |
| print("\n YOUR TASKS:)") | |
| print("-" * 30) | |
| for i, task in enumerate(tasks, 1): | |
| status = ":)" if task.get('done') else ":()" | |
| print(f"{i}. {status} {task['title']} ({task['category']})") | |
| print("-" * 30) | |
| def add_task(tasks): | |
| """Add new task""" | |
| title = input("Enter task title: ") | |
| category = input("Enter category (work/personal/other): ") | |
| tasks.append({'title': title, 'category': category, 'done': False}) | |
| print("Task added! ") | |
| def toggle_task(tasks): | |
| """Mark task as done/undone""" | |
| show_tasks(tasks) | |
| if not tasks: | |
| return | |
| try: | |
| num = int(input("Enter task number to toggle (0 to cancel): ")) | |
| if 1 <= num <= len(tasks): | |
| tasks[num-1]['done'] = not tasks[num-1]['done'] | |
| print("Task updated ") | |
| else: | |
| print("Invalid number!") | |
| except ValueError: | |
| print("Please enter a number!") | |
| def main(): | |
| tasks = load_tasks() | |
| print(" Welcome to Simple To-Do List") | |
| while True: | |
| print("\n[1] Add task") | |
| print("[2] View tasks") | |
| print("[3] Toggle task done") | |
| print("[4] Quit") | |
| choice = input("Choose (1-4): ").strip() | |
| if choice == '1': | |
| add_task(tasks) | |
| elif choice == '2': | |
| show_tasks(tasks) | |
| elif choice == '3': | |
| toggle_task(tasks) | |
| elif choice == '4': | |
| save_tasks(tasks) | |
| print("Tasks saved! Bye ") | |
| break | |
| else: | |
| print("Oops, pick 1-4 please!") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment