I have been using AI a lot. When I say "a lot," I mean a lot. I feel like my brain has stopped thinking. That made me think I am turning into a vibe coder rather than a programmer. I need to revive that brain of mine that once used to work on projects without the help of any kind of AI. So, what I decided to do is build small projects that will take me at most 1 week to complete, but I am not allowed to use any kind of AI at all. So, the first project I am going to build is a really basic one, a CLI task manager application. Nothing fancy, just to get started with the syntax and basic functions. I will document everything and publish it here, and I am planning to keep it raw, write my thinking process, and add the errors that I am stumbling over. How I plan things and so on. Let's start with the planning phase.
For this application, I will keep it pretty simple. I need a few basic functions to build all the features. Now what features do I need?
- Adding a task
- Editing a task
- Deleting a task
- Check or Uncheck a task
These are the basic features I need. So, I can write dedicated functions for each of them. I'll need 4 different functions, which will perform these tasks. I might need some helper functions. I will write every code in one single file, but I will use a class. It's not like I really need to, but it's a good refresher, so why not? Okay, now the million-dollar question: How do I store the data? Do I need a database or something? I think that's overkill for this simple project. I will simply use a JSON file to store the data so that I can really use all the tasks even after I have terminated the program.
For the start of this project, I will first store everything in a dictionary, and if I run everything correctly, I will push that to the JSON file, because JSON and dictionaries are quite similar. Let's get started with the project.
First, I will create a main.py file and start working; that's going to be our only file that I need for this project. In case you are curious, I am using VS Code.
Now, confession time, I literally forgot how to structure a class. So, I quickly looked up the syntax. So, I went to the official Python docs, NO AI, and this is what I found: I was right.
I was trying to write a class, and then I remembered I needed a dictionary first. So, this is the dictionary.

task_dict = {
"id":1234,
"task": "Testing the task",
"status":0
}
class Task:
def add_task(task_name):
pass
print(task_dict)
This is the part I wrote to check how the dictionary is going to be. I will empty this dictionary, and now I need to add information to it. But this is the structure.
I wrote this chunk of code, and I see a problem.
task_dict = {}
class Task:
def add_task(self,task_name):
task = {"id":1,"task":"test","status":0}
return task
task = Task()
task_dict = task.add_task("test")
task_dict = task.add_task("test")
print(task_dict)
It adds the task, but it doesn't append it. How about I change the task_dict to task_list and use the built-in append function?
task_dict = []
class Task:
def add_task(self,task_name):
task = {"id":1,"task":"test","status":0}
return task
task = Task()
task_dict.append(task.add_task("test"))
task_dict.append(task.add_task("test"))
print(task_dict)
[{'id': 1, 'task': 'test', 'status': 0}, {'id': 1, 'task': 'test', 'status': 0}]
Better! Now I know how to add a task, so I can start adding actual tasks. First, I will write my own random number generator function, or more precisely, random_id_generator, to generate an ID. I don't want it to have 1,2,3 as an ID, and when I delete it, it becomes like 1,4,5,8...
I found this information on Reddit: "The first type is called a pseudorandom number generator (PRNG). These don't actually generate random numbers, just numbers that have a 'pretty good' variability. PRNGs can be pretty simple, like 1 or 2 lines of code, and mostly involving basic arithmetic. They usually have patterns that are pretty easy to find after a while, so they aren't considered secure. There's no magic here. These are just equations that humans can't easily predict the next output of."
So, turns out I need to learn that algorithm. From GeeksforGeeks, I got this formula, and I want to test what it actually does:
So, I wrote this code.
def random_id_generator():
Xn = 5
c = 7
for a in range(5):
for m in range(2,10,3):
number = (a*Xn+c) % m
print(number)
Although I am getting a random number, it's the same random number because it's just doing the exact same math every time, so it is as useless as me writing the number myself. I have to figure out something that will do different things every time. Okay, I just fixed the code.
def random_id_generator(Xn):
c = 19
for a in range(5):
number = (a*Xn+c) % 7
print(number)
From an artice of FreecodeCamp I learnt about the algorithm and what I was missing was giving the seed. I needed to change the seed or starting value, in my case Xn. So, every time I pass a different seed I get a different value. This is how it looks:
Pass the seed: 1
5
6
0
1
2
Pass the seed: 2
5
0
2
4
6
Pass the seed: 3
5
1
4
0
3
And the way I wrote the formula, the good thing is it always has the 5 at the beginning, which I like. So, this function is implemented, and now I can literally use it inside of my add_Task function. When I tried to write the function, I realized I am just getting the numbers separately, so I have to convert them into a single number. I did a quick Google search and figured it out again using the list.
def random_id_generator(Xn):
c = 19
list_of_num = []
for a in range(5):
result = (a*Xn+c) % 7
list_of_num.append(result)
number = int(''.join(str(x) for x in list_of_num))
print(type(number))
What it basically does is it first creates a simple empty list and appends all the numbers in that list that have been generated for this seed and then joins them and converts them to one single number. Now, I think it is complete.
Finally, changing that print to return, I wrote the complete code to add a task, and it is giving me this output.
def add_task(self,task_name,id):
generate_id = random_id_generator(id)
task = {
"id":generate_id,
"task":task_name,
"status":0
}
task_dict.append(task)
print("Task added successfully!")
[Output]
[{'id': 56012, 'task': 'test', 'status': 0}, {'id': 50246, 'task': 'test2', 'status': 0}]
Now, let's move on to editing the task. To edit a task, first we need to find the task. I wrote a find_task helper function to find the task.
def finding_task(id):
for i in range(len(task_dict)):
if id == task_dict[i]["id"]:
return i
else:
return -1
What it is doing is basically looping the entire list and checking if the id matches the id we have given. If the answer is yes, it returns that index that we can use, and if not, it returns a static error code -1, which, btw, I decided to return so that I can put a check.
After testing the code I realized I have caused a major logical flaw. The moment it can't find the index, it returns -1, and that causes the function to terminate. So, I rewrote it like this:
def finding_task(id):
index = -1
for i in range(len(task_dict)):
if id == task_dict[i]["id"]:
index = i
else:
index = -1
return index
Now, I can move on to the edit function. It has a bunch of inputs, and using the helper function, other than that, it's pretty straightforward.
def edit_task(self):
print('''
What do you want to edit?
1. Task
2. Status
choose between 1 or 2.
''')
userChoice = int(input("Choice: "))
if userChoice != 1 and userChoice != 2:
print("Invalid choice. Try again!")
return
id = int(input("Enter the id of the task you want to edit: "))
id_index = finding_task(id)
if id_index == -1:
print("Couldn't find the id.")
return
if userChoice == 1:
task_name = input("Enter the new task name: ")
temp = task_dict[id_index]["task"]
task_dict[id_index]["task"] = task_name
print(f"{temp} has been changed to {task_name}")
elif userChoice == 2:
print(
'''
Change the status.
0. Haven't done yet
1. Done
'''
)
status = int(input("Enter your choice: "))
if status != 0 and status != 1:
print("Invalid status update.")
temp = task_dict[id_index]["status"]
task_dict[id_index]["status"] = status
print(f"Status {temp} has been changed to {status}")
This is the delete function. I did a bit of trial and error so that I could figure it out, and I did take a sneaky approach.
def delete_task(self):
id = int(input("Enter the id of the task you want to delete: "))
id_index = finding_task(id)
task_dict[id_index].clear()
task_dict.remove({})
Here I first cleared the dictionary so that I know that's going to show as "{}" in the list, and then I just removed it.
Now I just wrote a display function, which is quite unnecessary, but I wrote it to polish the application.
def display_tasks(self):
print(
f'''
{'='*60}
Id{" "*10} Task{" "*10}Status
{'='*60}
'''
)
for i in range(len(task_dict)):
if task_dict[i]["status"] == 0:
show = "Not Done"
else:
show = "Done"
print(
f'''
{task_dict[i]["id"]}{" "*9} {task_dict[i]["task"]}{" "*9}{show}
'''
)
Now let's just write the main loop so that it always works and we'll be done with the first version which doesn't save the data yet.
task = Task()
# task_dict.append(task.add_task("test2",2))
choice = 1
seed = 1
while choice !=0:
print(
'''
Welcome to your CLI Task Manager. What do you want to do today?
1. Display all your tasks.
2. Add a new task.
3. Edit an existing task.
4. Delete a task
0. Quit the program
'''
)
answer = int(input("Enter your choice: "))
if answer == 0:
choice = 0
print("Quiting program")
break
if answer == 1:
task.display_tasks()
elif answer == 2:
new_task = input("Task: ")
task.add_task(new_task,seed)
seed+=1
elif answer == 3:
task.edit_task()
elif answer == 4:
task.delete_task()
else:
print("Invalid choice")
Now I implemented the json by finding some examples from the stackoverflow
import json
try:
with open('data.json', 'r') as file:
task_dict = json.load(file)
print("File data =", type(task_dict))
except FileNotFoundError:
task_dict = []
print("Error: The file 'data.json' was not found.")
with open("data.json", "w") as final:
json.dump(task_dict, final, indent=2, default=lambda x: list(x) if isinstance(x, tuple) else str(x))
print("Data written to data.json")
Now it is a fully functioning application.
if you want you can look at the full code from my
github: https://github.com/siamliam12/No-Brainer.git


Top comments (0)