Skip to content

Commit 6e520b4

Browse files
authored
Merge pull request #16 from codeasarjun/to-do-list
To do list
2 parents e386bd4 + 69892ad commit 6e520b4

File tree

7 files changed

+93
-1
lines changed

7 files changed

+93
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.txt
2-
*test_1.py
2+
*test_1.py
3+
__pycache__/

projects/todo-list/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This is a simple command-line To-Do List application built in Python. It allows users to manage their tasks by adding, viewing, and removing them. The application uses a JSON file for persistent storage, so tasks are saved between sessions.
2+
3+
- **`core/`**: Contains core functionality for managing tasks and file operations.
4+
- **`load_save.py`**: Functions to load and save tasks to a JSON file.
5+
- **`task_management.py`**: Functions to add, view, and remove tasks.
6+
- **`utils.py`**: (Optional) Additional helper functions.
7+
- **`todo_list.py`**: The main script that provides a command-line interface for interacting with the To-Do List.
8+
- **`tasks.json`**: JSON file used for storing tasks persistently.
9+
10+
11+
## Interact with the To-Do List
12+
13+
1. **Add Task:** Select option 1 and enter the task description.
14+
2. **View Tasks:** Select option 2 to see a list of current tasks.
15+
3. **Remove Task:** Select option 3 and enter the task number to remove it.
16+
4. **Exit:** Select option 4 to save tasks and exit the application.

projects/todo-list/app.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from core.load_save import load_tasks, save_tasks
2+
from core.task_management import add_task, view_tasks, remove_task
3+
4+
def main():
5+
filename = "tasks.json"
6+
task_list = load_tasks(filename)
7+
8+
while True:
9+
print("\nTo-Do List Menu")
10+
print("1. Add Task")
11+
print("2. View Tasks")
12+
print("3. Remove Task")
13+
print("4. Exit")
14+
15+
choice = input("Choose an option (1/2/3/4): ")
16+
17+
if choice == '1':
18+
task = input("Enter the task: ")
19+
add_task(task_list, task)
20+
elif choice == '2':
21+
view_tasks(task_list)
22+
elif choice == '3':
23+
view_tasks(task_list)
24+
try:
25+
task_number = int(input("Enter the task number to remove: "))
26+
remove_task(task_list, task_number)
27+
except ValueError:
28+
print("Invalid input. Please enter a number.")
29+
elif choice == '4':
30+
save_tasks(filename, task_list)
31+
print("Tasks saved. Exiting...")
32+
break
33+
else:
34+
print("Invalid choice. Please select 1, 2, 3, or 4.")
35+
36+
if __name__ == "__main__":
37+
main()

projects/todo-list/core/__init__.py

Whitespace-only changes.

projects/todo-list/core/load_save.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import json
2+
import os
3+
4+
def load_tasks(filename):
5+
if not os.path.isfile(filename):
6+
with open(filename, 'w') as file:
7+
json.dump([], file, indent=4)
8+
9+
# Load tasks from the file
10+
with open(filename, 'r') as file:
11+
tasks = json.load(file)
12+
13+
return tasks
14+
15+
def save_tasks(filename, task_list):
16+
with open(filename, 'w') as file:
17+
json.dump(task_list, file, indent=4)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def add_task(task_list, task):
2+
task_list.append(task)
3+
print(f"Task '{task}' added.")
4+
5+
def view_tasks(task_list):
6+
if not task_list:
7+
print("No tasks found.")
8+
else:
9+
print("To-Do List:")
10+
for index, task in enumerate(task_list, start=1):
11+
print(f"{index}. {task}")
12+
13+
def remove_task(task_list, task_number):
14+
try:
15+
removed_task = task_list.pop(task_number - 1)
16+
print(f"Task '{removed_task}' removed.")
17+
except IndexError:
18+
print("Invalid task number.")

projects/todo-list/tasks.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
"Need to go the market"
3+
]

0 commit comments

Comments
 (0)