diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99f3a19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +#ignore the runtime storage files +.vscode/ +tasks.json \ No newline at end of file diff --git a/todo.py b/todo.py index a72fa61..2ef3ec0 100644 --- a/todo.py +++ b/todo.py @@ -1,10 +1,19 @@ +import json +import os + class TodoApp: - def __init__(self): + def __init__(self, filename="tasks.json"): + self.filename = filename self.tasks = [] - def add_task(self, task): - self.tasks.append({"task": task, "completed": False}) - print(f"Task '{task}' added!") + # Add a new priority feature for tasks when adding them + def add_task(self, task, priority="Medium"): + self.tasks.append({ + "task": task, + "priority": priority, + "completed": False + }) + print(f"Task '{task}' added with priority '{priority}'!") def remove_task(self, task_index): try: @@ -20,14 +29,20 @@ def mark_completed(self, task_index): except IndexError: print("Invalid task index.") + # Updated view to show priority and completion status def view_tasks(self): if not self.tasks: print("No tasks to show.") else: for idx, task in enumerate(self.tasks): status = "Completed" if task["completed"] else "Not Completed" - print(f"{idx}. {task['task']} - {status}") + print(f"{idx}. {task['task']} - {task['priority']} - {status}") + def load_tasks(self): + if os.path.exists(self.filename): + with open(self.filename, "r") as f: + self.tasks = json.load(f) + print(f"Loaded {len(self.tasks)} task(s) from {self.filename}") def main(): todo_app = TodoApp() @@ -41,9 +56,11 @@ def main(): print("5. Exit") choice = input("Choose an option: ") + # updated to handle priority when adding tasks if choice == '1': task = input("Enter task: ") - todo_app.add_task(task) + priority = input("Enter priority (High/Medium/Low): ").capitalize() + todo_app.add_task(task, priority) elif choice == '2': todo_app.view_tasks() try: @@ -61,6 +78,8 @@ def main(): elif choice == '4': todo_app.view_tasks() elif choice == '5': + # Save on exit + todo_app.save_tasks() print("Goodbye!") break else: