Generate Jupyter notebook practice challenges for Python. Use when the user wants practice problems, coding exercises, study notebooks, or drill questions for pandas or algorithms.
Generate a Jupyter notebook filled with practice challenges and questions. Challenges cover pandas (data manipulation, cleaning, exploration, time series) and algorithms (vanilla Python data structures, sorting, searching, recursion).
Follow the rules in RULES.md.
Gather parameters using AskUserQuestion. Ask the user:
notebooks/practice.Check for previous exercises (if folder provided):
Generate varied question data using the helper scripts (see Scripts below). For every notebook:
random_tickers.py to pick a fresh set of tickers for the session.fetch_price_data.py to get real market data for those tickers. Use the --format code or --format returns flag to get a Python snippet you can embed in the notebook setup cell.random_data.py to generate random numbers, date ranges, or messy DataFrames as needed by the questions.Build the notebook using generate_notebook.py:
--bank to pull pre-written questions and randomize:
python scripts/generate_notebook.py \
--bank questions/bank.json \
--category pandas --difficulty easy --count 5 \
--output notebooks/practice
python scripts/generate_notebook.py \
--category pandas --difficulty medium \
--output notebooks/practice < /tmp/questions.json
prompt (str) and solution (str). Optional fields:
hint (str, will be rendered in a collapsed <details> tag). Hints must be hidden by default.setup (str, per-question code cell), subcategory (str).Customize the setup cell — replace the template's sample data with the real market data fetched in step 3. Use the output of fetch_price_data.py --format code or --format returns as the setup cell content.
Confirm the notebook path to the user when finished.
Each generated notebook must follow this structure:
fetch_price_data.py.<details><summary>💡 Hint</summary>...</details> tag (initially collapsed).<details><summary>✅ Solution</summary>...</details> tag so the user can reveal it.All scripts live in scripts/ and are run from that directory.
generate_notebook.pyBuilds a .ipynb file from a category template + question data. Uses nbformat.
# From question bank:
python scripts/generate_notebook.py --bank questions/bank.json \
--category pandas --subcategory series --difficulty easy --count 5 --output notebooks/practice
# From a JSON file of custom questions:
python scripts/generate_notebook.py --questions /tmp/my_questions.json \
--category algorithms --difficulty hard --output notebooks/practice
# From stdin:
cat questions.json | python scripts/generate_notebook.py --category pandas --output notebooks/practice
random_tickers.pyPick random ticker symbols to use in questions. Avoids repeating the same tickers.
python scripts/random_tickers.py --count 4 # 4 random tickers
python scripts/random_tickers.py --count 3 --sector tech # from tech sector
python scripts/random_tickers.py --count 5 --diverse # one per sector
python scripts/random_tickers.py --list-sectors # show all sectors
Use this every time you generate a notebook to ensure fresh ticker sets.
fetch_price_data.pyFetch real stock price data from Yahoo Finance via yfinance. Embed the output in notebook setup cells so students work with real market data.
# Get a code snippet to embed in the notebook
python scripts/fetch_price_data.py --tickers AAPL MSFT TSLA --period 6mo --format code
# Get daily returns as a code snippet
python scripts/fetch_price_data.py --tickers AAPL MSFT --period 3mo --format returns
# Random tickers + real data
python scripts/fetch_price_data.py --random 4 --period 1y --format code
# Save as CSV
python scripts/fetch_price_data.py --tickers SPY QQQ --start 2023-01-01 --end 2024-01-01 --output prices.csv
random_data.pyGenerate random numbers, date ranges, names, and messy DataFrames for question variety.
python scripts/random_data.py --type integers --count 10 --min 1 --max 100
python scripts/random_data.py --type floats --count 5 --min -0.05 --max 0.05
python scripts/random_data.py --type date_range --start 2020-01-01 --periods 30 --freq B
python scripts/random_data.py --type names --count 8
python scripts/random_data.py --type messy_dataframe --rows 20
Use --type messy_dataframe to generate data-cleaning exercises with realistic problems (missing values, inconsistent casing, whitespace, bad types, duplicates).
Category-specific notebook templates live in templates/. Each template provides:
{{difficulty}}, {{date}}, {{count}}, {{subcategories}} placeholders| Template | File | Description |
|---|---|---|
| Pandas | templates/pandas_template.ipynb | Imports pandas, numpy, matplotlib, seaborn. Pre-built sample datasets (stock_returns, messy_data, sectors). |
| Algorithms | templates/algorithms_template.ipynb | Imports collections, heapq, math, typing. Includes a check() helper for testing solutions. |
Pre-written questions are stored in questions/bank.json. The bank is organized as:
{ category: { subcategory: { difficulty: [question, ...] } } }
Each question has: prompt, solution, and optionally hint and setup.
Refer to references/PANDAS_NOTE.md for the topic tree and references/PANDAS_FOR_DATA_SCIENCE.md for functions and techniques. Use examples/PANDAS_EXAMPLES.md for sample data patterns.
Subcategories:
Focused on vanilla Python (no external libraries).
Subcategories: