Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ignore the runtime storage files
.vscode/
tasks.json
31 changes: 25 additions & 6 deletions todo.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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:
Expand Down