0% found this document useful (0 votes)
3 views3 pages

Source Code Documentation

The document outlines the implementation of a todo list program in Python, detailing the import of necessary libraries, file handling, and task management functionalities. It describes how to view, add, complete, and filter tasks, as well as how to save data to a text file. The program also includes a feature to provide user feedback based on the percentage of completed tasks.

Uploaded by

Emmanuel Fred
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Source Code Documentation

The document outlines the implementation of a todo list program in Python, detailing the import of necessary libraries, file handling, and task management functionalities. It describes how to view, add, complete, and filter tasks, as well as how to save data to a text file. The program also includes a feature to provide user feedback based on the percentage of completed tasks.

Uploaded by

Emmanuel Fred
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

GROUP 2 PROJECT DOCUMENTATION

Import and fxn definition.

• import datetime: This line tells Python to import date and time because I will need the to-
do list to tally with the present date.

• data_file = "group2_TodoList.txt": This line saves the code as a text file and prevents the
data from being lost when the system is turned off.

• def group2_project(): This line defines my function. I called the function group2_project.

• tasks = []: This line creates an empty list where I will put all my tasks, their allocated time,
and their respective statuses.

File setup.

• try: When the program starts, it tries to open group2_TodoList.txt. If it is the first time
running the code, that file doesn't exist yet. Without “try:”, Python would see a missing file
and crash immediately. With it, the program continues, skips the error, and simply starts
with an empty list instead.

• file = open(data_file, "r"): This line instructs Python to open the text file from its directory
and read it. “r” means read.

• for line in file: This line tells Python to iterate through every line in my text file and read
everything that is there.

• parts = [Link]().split("|"): First, this line removes all the unnecessary whitespaces
between the texts. Secondly, it finds the "|" that is already there to separate the text into
pieces.
• task_data = { ... }: This line puts those headings (tasks, time, status) into a dictionary.
• [Link](task_data): This line puts the dictionary that contains those items into the
empty list that was initially created.
• [Link](): This line closes the text file.

• except: This line is what tells Python that if it checks and does not see any previous item,
then it should proceed to create a new one for me.

Date integration.

• today = [Link](): This line commands Python to stamp the present date on the
top of the todo list.
• while True: This line makes use of a while loop that will tell Python to keep asking you for
instructions until you tell it to stop.
• print(...): This line tells Python to display your input data to the screen.

• choice = input(...): This line tells the user to input any option from the listed ones above.

Option 1: Viewing the chore(s).

• if choice == '1': This line tells Python to make the user “View Tasks” if he/she chooses
option 1.

• for item in tasks: This line pulls out every folder one by one from the list called “tasks.”

• status = "Done" if item["done"] == True else "Pending": This line tells Python to mark a
task as “Done” if it satisfies the item “done” in the list; else, Python should mark the task
as “Pending.”

• print(item["task"], "---", item["time"], "---", status): This line tells Python to arrange the
items in this order: “task, time, status.”

Option 2: Chore(s) addition.

• elif choice == '2': This line tells Python to make the user “Add Tasks” if he/she chooses
option 2.

• task_name = input(...): This line instructs the user to input a task name.

• task_time = input(...): This line instructs the user to input a task time.
• new_entry = {"task": task_name, "time": task_time, "done": False}: This line tells Python
to create another dictionary and insert all the data you input in that order. Then it sets the
task’s status. “done” to “false” because the user has not done anything yet.

• [Link](new_entry): This line tells Python to add all the data inside the dictionary
into the initially created task list.

Option 3: Completing a chore


• elif choice == '3': This line tells Python to mark a task as “completed” if the user chooses
option 3.

• for i in range(len(tasks)): This line tells Python to list the task numbers in the format 1, 2,
3, etc.

• index = int(input(...)): This line allows the user to manually input into Python the number
of tasks that he/she completed.

• tasks[index - 1]["done"] = True: This line tells Python to go back to the specific line of
code that initially had “False” and convert it to “True” only for the completed tasks.
Option 4 & 5: Filtering chores

• elif choice == '4': and elif choice == '5': These lines are filters.

• if item["done"] == True: This line tells Python to iterate through the “tasks” list and print
only the items that are “Done.”

• if item["done"] == False: This line tells Python to iterate through the “tasks” list and print
only the items still “pending.”

Option 6: Closing the program

• elif choice == '6': This line begins the instruction to exit the todo list.

• total = len(tasks): The line tells Python to count how many chores are in the list named
“tasks.”

• completed_count = completed_count + 1: This line tells Python to add one to its scoreboard
named “completed_count” every time it finds a “True.”

• percent = (completed_count / total) * 100: This line calculates the percentage of tasks that
were completed out of the total number of tasks.

• if percent >= 70: This line tells Python to give the user a heartwarming note if he/she
completed up to or more than 70% of the tasks. Else, Python would tell the user to try
harder tomorrow.

• file = open(data_file, "w"): This line tells Python to write new data in the “.txt” file
(notepad) anytime the user feeds new data into the program. “w” means write.

• line = item["task"] + "|" + ...: This line tells Python to store all the todo list data in this
format: Task|Time|Status

• [Link](line): This line saves the data directly from the Python script into my notepad.

• break: This line brings an end to the loop that was initially opened with “while true.”

• group2_project(): This line calls the function and makes Python start executing the results.

You might also like