Build a Tiny Python Study Log Before Buying a Course
by zhadovsergey in Circuits > Computers
17 Views, 0 Favorites, 0 Comments
Build a Tiny Python Study Log Before Buying a Course
Build a command-line study log that remembers a topic and the minutes you spent on it. You will create one Python file, run two example sessions, and test what happens when the input is wrong. The completed program stores its data in a local JSON file.
This KGAM learning project was prepared with AI assistance. The source code was executed and checked; the main image displays its actual captured output. No paid tools or external Python packages are needed.
Supplies
A computer with Python 3 installed; a plain text editor; a terminal; a folder where you can save files. The code (study_log.py), captured example run (study-log-demo.txt), and verification notes (study-log-tests.txt) are attached separately in Step 2.
Set Up One Folder
Install Python 3 from https://www.python.org/downloads/ if it is not already available. Create a folder called study-log and open a terminal there. Run python --version. On macOS or Linux, your command may be python3; use that same command throughout.
A plain text editor is enough. Save the code as study_log.py, not study_log.py.txt. Keep this exercise in its own folder: the default data file is written to the current working directory.
Create the Program
Save the attached study_log.py in that folder. Open the file in your text editor and read it before running it. It uses argparse for commands, json for storage, and pathlib for paths. All three belong to the Python standard library.
The load_entries function checks the stored data before we change it. The add command rejects a blank topic or zero/negative duration. A temporary file is written first and then replaces the log. This is a single-user learning tool; do not run simultaneous writers against the same file.
Record Two Example Sessions
Run these commands one at a time:
python study_log.py list
python study_log.py add 25 "Python loops"
python study_log.py add 15 "JSON files"
python study_log.py list
The first command should say No sessions yet. The last command should show two entries and Total: 40 min. These are example durations, not a claim about how long you need to learn Python.
Close the terminal, reopen it in the same folder, and run the list command again. The entries should still be there because they live in study-log.json. The main output image was rendered from the actual captured run of this program.
Try Mistakes and Preserve the Data
Run python study_log.py add -5 "Loops". It should report an error, and list should still show 40 minutes. Try a blank topic with python study_log.py add 5 " ". That should also fail.
To try a damaged file without touching your log, create a separate plain text file called broken.json containing only {broken. Run python study_log.py --file broken.json list. The program reports that it cannot read the log. It leaves that file alone instead of replacing it with an empty list.
The supplied version was tested with an empty log, two additions in separate processes, the persisted total, negative minutes, blank topics, noninteger input, and malformed JSON. The transcript and checks are attached as study-log-demo.txt and study-log-tests.txt in Step 2.
Change One Thing Before Choosing a Course
Now add a total command that prints only the total minutes. Start by predicting which lines must change. Add a new parser command, then decide how it should share the calculation already used by list. Run the original examples again after your edit.
If you get stuck, write down the exact gap: command-line arguments, loops, file paths, or JSON. That gives you a concrete question to ask a teacher or a course syllabus. Completing this exercise does not measure job readiness or prove that you do not need a course. It gives you a small piece of working software you can explain and change.
Keep backups of any log you care about. This example has no locking, synchronization, editing command, or encryption. It is intended for local practice. Reference documentation: https://docs.python.org/3/library/argparse.html and https://docs.python.org/3/library/json.html .