Day 48 of 100 Days Coding Challenge: Python
After days of tinkering with this book tracker like a mad librarian with a barcode scanner, I realized something important: I don’t want to be the poor soul manually updating the genre-color dictionary every time I read something new. Let’s face it—“User-friendly” doesn’t mean much when the only user is me, and I still find myself muttering, “Why isn’t this thing purple?” every time I forget to update the genre list.
So today’s quest? Build a feature that lets me add new genres and assign them pretty little colors on the fly—without breaking the whole program or sending myself into a debugging spiral. It’s not just about aesthetics. It’s about freedom. Genre freedom. Color-coded, quarter-sorted, reader-powered freedom.
Today’s Motivation / Challenge
Sometimes, your biggest obstacle is your past self—the one who hardcoded things thinking they’d never change. Past Me didn’t expect Present Me to branch out from Fantasy and Sci-Fi. But here we are, reading historical dramas and the occasional poem. Rather than letting my program judge me for my evolving tastes, I figured it was time to teach it some manners. Today’s challenge was about flexibility: giving my tracker the power to grow as my reading list does.
Purpose of the Code (Object)
This update makes the book tracker more interactive and adaptable. Instead of manually editing the genre-color dictionary every time I pick up a new type of book, I can now add a new genre and assign it a color from within the program itself. It’s one small line of code for me, one giant leap for my sanity.
AI Prompt:
“Add a function that allows the user to update the genre-color dictionary during runtime without editing the code directly.”
Functions & Features
- Add and assign a new genre with a custom color
- Auto-updated pie and bar charts include the new genre
- Prevents duplicate genres by checking existing entries
- Keeps your genre list as fresh as your reading habits
Requirements / Setup
You’ll need:
pip install matplotlib pandas
Python 3.8+ is recommended, but it should work on most modern versions.
Minimal Code Sample
def add_new_genre_color(genre_color_dict, new_genre, new_color):
if new_genre in genre_color_dict:
print(f”{new_genre} already exists with color {genre_color_dict[new_genre]}.”)
else:
genre_color_dict[new_genre] = new_color
print(f”Added new genre: {new_genre} with color {new_color}.”)
This simple function updates the dictionary in real time, without opening the script file.
Notes / Lessons Learned
One of the biggest challenges I’m facing now is the trail of code left behind by my earlier, less organized self. Back then, I hardcoded colors like a kid with a new box of crayons and zero aesthetic restraint. The result? A genre list that doesn’t always match my pie chart, or my mood.
Today, I tested the new feature by adding “Mystery” as a genre. I even fabricated a “Mystery Book” just to make sure it worked. Spoiler: it did. And yes, it showed up beautifully in the pie chart too. Eventually, I might scrap the rigid GENRE_COLORS dictionary altogether and switch to a fully dynamic model—one that builds as I read. One genre at a time.
Optional Ideas for Expansion
- Save updated genres and colors to a JSON file so they persist after the script closes
- Add a feature to suggest random colors if the user can’t pick one
- Let users rename or delete genres via a menu option
