Day 59 of 100 Days Coding Challenge: Python
Yesterday, I caught myself on the edge of a rookie mistake: copying the same chunk of “fetch price” code into every place that needed it. It was like déjà vu with worse indentation. So I took a breath, cleaned it up, and extracted that logic into a shiny, single-purpose function: get_price(). Now, anytime I need the current price of a stock, I just call one clean little line. And if I ever want to swap out Yahoo Finance for Alpha Vantage—or carrier pigeons, who knows—I only have to update it in one place.
Unlike my previous project (the slightly chaotic book tracker that looked like it was written in a storm), this time I’ve actually thought about structure. I outlined a rough roadmap and started slicing features into small, logical pieces. Turns out, coding for your future self is a real kindness. It’s already making the script easier to manage, and I haven’t even spilled coffee on it yet.
I also added an extra feature that turned out to be more useful than expected: the ability to check the current price of a single stock on demand. It’s perfect for those moments when I randomly wonder, “How’s TSLA doing today?” or “Is MSFT still climbing?” Now I don’t have to scroll through my entire portfolio—I just type, fetch, and boom. Market curiosity satisfied.
Today’s Motivation / Challenge
This project is starting to feel like a real tool, not just a list of stock symbols collecting digital dust. But with functionality growing, it was time to tidy up the code before it turned into a spaghetti bowl. By modularizing the price-fetching logic, I gave myself room to grow—because adding new features is so much easier when your code isn’t held together with duct tape and denial.
Purpose of the Code (Object)
The script now includes a reusable function, get_price(), that handles all price-fetching tasks. It simplifies the process of displaying current prices and opens the door to adding new features without clutter. I also added a quick price-check tool for any stock—not just ones in your portfolio.
AI Prompt:
Refactor price-fetching logic into a reusable Python function using yfinance. Add an option to check the real-time price of any single stock.
Functions & Features
- Add or remove stock symbols
- View your portfolio with current prices
- Fetch real-time price for any single stock
- Show stock symbol list
- Exit the program (option 99, always last)
Requirements / Setup
pip install yfinance
Python 3.8+ recommended. Use a virtual environment if possible for clean installs.
Minimal Code Sample
python
CopyEdit
def get_price(symbol):
ticker = yf.Ticker(symbol)
return ticker.info.get(“regularMarketPrice”)
A reusable function to get the latest market price for a stock symbol.
Notes / Lessons Learned
The key to keeping a growing script from turning into chaos? Organization. Even with AI in your corner, you still need to think ahead. During my book tracker project, I just tacked on features as they came to mind—resulting in a menu that looked like a word jumble and an exit function mysteriously wedged in the middle of everything.
This time, it’s different. Each function has a purpose, and I’m building with intention. Adding the “check a specific stock” feature was fast and satisfying. I tested it with TSLA and MSFT—worked like a charm. It’s amazing what a little structure (and a lot less clutter) can do.
Optional Ideas for Expansion
- Add error handling for invalid or misspelled stock symbols
- Include the timestamp of last price update
- Build a search history so you can revisit recently checked stocks
This project is starting to feel less like a toy and more like a tool. Clean code, clear menus, and real data—what’s not to love?

