Appendix G: Answers to Selected Exercises

This appendix provides detailed solutions to selected exercises from each chapter. These solutions demonstrate proper problem-solving approaches, calculation methods, and analytical reasoning. Students are encouraged to attempt problems independently before consulting these answers.


Chapter 3: Python Environment Setup

Exercise 4: Version Check Script

Problem: Create a script that checks installed package versions against minimum requirements.

Solution:

"""Check installed package versions against requirements."""

from packaging import version
import importlib

REQUIREMENTS = {
    'pandas': '2.0.0',
    'numpy': '1.24.0',
    'matplotlib': '3.7.0',
    'seaborn': '0.12.0'
}

def check_version(package_name, min_version):
    """Check if installed version meets minimum requirement."""
    try:
        module = importlib.import_module(package_name)
        installed = module.__version__
        meets_requirement = version.parse(installed) >= version.parse(min_version)
        status = "PASS" if meets_requirement else "FAIL"
        return installed, status
    except ImportError:
        return "NOT INSTALLED", "FAIL"

def main():
    print("Package Version Check")
    print("=" * 30)

    all_pass = True
    for package, min_ver in REQUIREMENTS.items():
        installed, status = check_version(package, min_ver)
        print(f"{package}: {installed} [{status}]")
        if status == "FAIL":
            all_pass = False

    print("=" * 30)
    if all_pass:
        print("All requirements satisfied!")
    else:
        print("Some requirements not met.")

if __name__ == "__main__":
    main()

Expected Output:

Package Version Check
==============================
pandas: 2.0.3 [PASS]
numpy: 1.24.3 [PASS]
matplotlib: 3.7.2 [PASS]
seaborn: 0.12.2 [PASS]
==============================
All requirements satisfied!

Key Concepts: This exercise demonstrates importing modules dynamically, version comparison using the packaging library, and structured output formatting.


Exercise 9: Creating Your First Virtual Environment

Problem: Create a virtual environment for a basketball analytics project.

Solution:

# Step 1: Create directory
mkdir nba_analysis
cd nba_analysis

# Step 2: Create virtual environment
python -m venv venv

# Step 3: Activate environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

# Step 4: Verify activation
which python    # Should show path within venv directory
python --version

# Step 5: Install packages
pip install pandas numpy

# Step 6: Verify installation
pip list

# Step 7: Deactivate
deactivate

Verification Output:

(venv) $ which python
/path/to/nba_analysis/venv/bin/python

(venv) $ pip list
Package    Version
---------- -------
numpy      1.24.3
pandas     2.0.3
pip        23.2.1

Key Concepts: Virtual environments isolate project dependencies, preventing conflicts between projects. Always activate the environment before installing packages.


Exercise 23: Git Basics

Problem: Initialize a Git repository with proper structure.

Solution:

# Step 1: Create and initialize
mkdir basketball_analytics
cd basketball_analytics
git init

# Step 2: Create .gitignore
cat > .gitignore << 'EOF'
# Python
__pycache__/
*.py[cod]
*$py.class
.Python
venv/
env/

# Jupyter
.ipynb_checkpoints/

# Data files (often too large for git)
*.csv
*.xlsx
data/

# Environment
.env
.env.local

# IDE
.vscode/
.idea/

# OS
.DS_Store
Thumbs.db
EOF

# Step 3: Create initial Python script
cat > analysis.py << 'EOF'
"""Basic basketball analysis script."""
import pandas as pd

def calculate_ppg(total_points, games_played):
    """Calculate points per game."""
    if games_played == 0:
        return 0.0
    return total_points / games_played

def calculate_ts_pct(points, fga, fta):
    """Calculate true shooting percentage."""
    tsa = fga + 0.44 * fta
    if tsa == 0:
        return 0.0
    return points / (2 * tsa)

if __name__ == "__main__":
    # Example usage
    print(f"PPG: {calculate_ppg(2100, 82):.1f}")
    print(f"TS%: {calculate_ts_pct(2100, 1500, 500):.3f}")
EOF

# Step 4: Stage and commit
git add .gitignore analysis.py
git commit -m "Initial commit: Add gitignore and analysis script"

# Step 5: View history
git log --oneline

# Step 6: Create and commit README
cat > README.md << 'EOF'
# Basketball Analytics Project

A Python project for analyzing basketball statistics.

## Setup
1. Create virtual environment: `python -m venv venv`
2. Activate: `source venv/bin/activate`
3. Install dependencies: `pip install -r requirements.txt`
EOF

git add README.md
git commit -m "Add README documentation"

Key Concepts: Good Git practices include meaningful commit messages, a comprehensive .gitignore file, and documentation from the start.


Chapter 6: Box Score Fundamentals

Exercise 1: Point Calculation

Problem: Calculate total points for each player.

Player 2PT FGM 3PT FGM FTM
Player A 8 3 5
Player B 12 0 7
Player C 4 6 2
Player D 6 4 8

Solution:

Points = (2PT FGM x 2) + (3PT FGM x 3) + (FTM x 1)

  • Player A: (8 x 2) + (3 x 3) + (5 x 1) = 16 + 9 + 5 = 30 points
  • Player B: (12 x 2) + (0 x 3) + (7 x 1) = 24 + 0 + 7 = 31 points
  • Player C: (4 x 2) + (6 x 3) + (2 x 1) = 8 + 18 + 2 = 28 points
  • Player D: (6 x 2) + (4 x 3) + (8 x 1) = 12 + 12 + 8 = 32 points

Key Insight: Player D scored the most despite having fewer 2-point field goals than Player B, demonstrating the value of three-point shooting and free throw attempts.


Exercise 9: Rebounding Rate

Problem: A center plays 34 minutes with 3 OREB and 9 DREB. Team rebounds: 48 (12 OREB, 36 DREB). Opponent rebounds: 44 (10 OREB, 34 DREB). Team minutes: 240.

Solution:

a) Offensive Rebound Percentage (ORB%):

$$ORB\% = 100 \times \frac{ORB \times (TmMP / 5)}{MP \times (TmORB + OppDRB)}$$

$$ORB\% = 100 \times \frac{3 \times (240 / 5)}{34 \times (12 + 34)} = 100 \times \frac{3 \times 48}{34 \times 46}$$

$$ORB\% = 100 \times \frac{144}{1564} = \mathbf{9.21\%}$$

b) Defensive Rebound Percentage (DRB%):

$$DRB\% = 100 \times \frac{DRB \times (TmMP / 5)}{MP \times (TmDRB + OppORB)}$$

$$DRB\% = 100 \times \frac{9 \times (240 / 5)}{34 \times (36 + 10)} = 100 \times \frac{9 \times 48}{34 \times 46}$$

$$DRB\% = 100 \times \frac{432}{1564} = \mathbf{27.62\%}$$

c) Total Rebound Percentage (TRB%):

$$TRB\% = 100 \times \frac{TRB \times (TmMP / 5)}{MP \times (TmTRB + OppTRB)}$$

$$TRB\% = 100 \times \frac{12 \times 48}{34 \times 92} = 100 \times \frac{576}{3128} = \mathbf{18.41\%}$$

Interpretation: This center grabbed about 18.4% of all available rebounds while on the court, with stronger defensive rebounding (27.6%) than offensive rebounding (9.2%). This is typical for most centers, as defensive rebounds are more readily available.


Exercise 29: Game Score Analysis

Problem: Calculate Game Score for the following performance: - 28 points, 10-18 FG, 3-6 3PT, 5-7 FT - 3 OREB, 8 DREB - 7 assists, 2 turnovers - 1 steal, 2 blocks - 3 personal fouls

Solution:

Game Score Formula: $$GS = PTS + 0.4 \cdot FGM - 0.7 \cdot FGA - 0.4 \cdot (FTA - FTM) + 0.7 \cdot ORB + 0.3 \cdot DRB + STL + 0.7 \cdot AST + 0.7 \cdot BLK - 0.4 \cdot PF - TOV$$

Substituting values: $$GS = 28 + 0.4(10) - 0.7(18) - 0.4(7-5) + 0.7(3) + 0.3(8) + 1 + 0.7(7) + 0.7(2) - 0.4(3) - 2$$

Breaking down each component: - Points: 28.0 - FGM bonus: +4.0 - FGA penalty: -12.6 - Missed FT penalty: -0.8 - OREB: +2.1 - DREB: +2.4 - STL: +1.0 - AST: +4.9 - BLK: +1.4 - PF penalty: -1.2 - TOV penalty: -2.0

$$GS = 28 + 4.0 - 12.6 - 0.8 + 2.1 + 2.4 + 1.0 + 4.9 + 1.4 - 1.2 - 2.0 = \mathbf{27.2}$$

Interpretation: A Game Score of 27.2 represents an excellent performance. According to standard interpretation: - 40+ = Outstanding - 30+ = Excellent - 20+ = Good - 10-20 = Average - Below 10 = Poor

This performance falls in the "Excellent" category, driven primarily by efficient scoring (28 points on 18 shots) and strong playmaking (7 assists vs. 2 turnovers).


Chapter 9: Advanced Box Score Metrics

Exercise 1: Basic Game Score

Problem: Calculate Game Score with: 28 PTS, 10-18 FG, 6-8 FT, 1 ORB, 5 DRB, 7 AST, 2 STL, 0 BLK, 3 PF, 4 TOV.

Solution:

$$GS = 28 + 0.4(10) - 0.7(18) - 0.4(8-6) + 0.7(1) + 0.3(5) + 2 + 0.7(7) + 0.7(0) - 0.4(3) - 4$$

$$GS = 28 + 4 - 12.6 - 0.8 + 0.7 + 1.5 + 2 + 4.9 + 0 - 1.2 - 4 = \mathbf{22.5}$$

Interpretation: A solid performance, slightly above "good" threshold. The 4 turnovers and lack of blocks bring down an otherwise strong scoring and playmaking line.


Exercise 7: Basic Usage Rate Calculation

Problem: Calculate Usage Rate for a player with 34 MIN, 18 FGA, 6 FTA, 3 TOV. Team totals: 240 MIN, 88 FGA, 24 FTA, 14 TOV.

Solution:

$$USG\% = 100 \times \frac{(FGA + 0.44 \times FTA + TOV) \times (TmMP/5)}{MP \times (TmFGA + 0.44 \times TmFTA + TmTOV)}$$

First, calculate the components: - Player possessions used: $18 + 0.44(6) + 3 = 18 + 2.64 + 3 = 23.64$ - Team possessions: $88 + 0.44(24) + 14 = 88 + 10.56 + 14 = 112.56$ - Time adjustment factor: $\frac{240/5}{34} = \frac{48}{34} = 1.412$

$$USG\% = 100 \times \frac{23.64 \times 48}{34 \times 112.56} = 100 \times \frac{1134.72}{3827.04} = \mathbf{29.65\%}$$

Interpretation: This player uses approximately 30% of team possessions while on the court, indicating a primary offensive option. League average usage is around 20%, so this represents high-volume offensive responsibility.


Exercise 13: Assist Percentage Calculation

Problem: Calculate AST% for a point guard with 32 MIN, 9 AST, 5 FGM. Team: 240 MIN, 42 FGM total.

Solution:

$$AST\% = 100 \times \frac{AST \times (TmMP/5)}{MP \times (TmFGM - FGM)}$$

Note: We subtract the player's own field goals since you cannot assist yourself.

$$AST\% = 100 \times \frac{9 \times (240/5)}{32 \times (42 - 5)} = 100 \times \frac{9 \times 48}{32 \times 37}$$

$$AST\% = 100 \times \frac{432}{1184} = \mathbf{36.49\%}$$

Interpretation: This point guard assisted on about 36.5% of teammate field goals while on the court. This is well above average (league average is around 15-20%) and indicates an elite playmaker. For context, the highest AST% seasons ever are around 50% (John Stockton, Steve Nash).


Chapter 12: Box Plus-Minus (BPM) and VORP

Exercise 1: True Shooting Percentage

Problem: Calculate TS% for each player.

Player Points FGA FTA
A 25.0 18 6
B 18.0 15 3
C 30.0 22 8
D 12.0 10 4

Solution:

$$TS\% = \frac{PTS}{2 \times (FGA + 0.44 \times FTA)}$$

Player A: $$TS\% = \frac{25}{2 \times (18 + 0.44 \times 6)} = \frac{25}{2 \times 20.64} = \frac{25}{41.28} = \mathbf{60.6\%}$$

Player B: $$TS\% = \frac{18}{2 \times (15 + 0.44 \times 3)} = \frac{18}{2 \times 16.32} = \frac{18}{32.64} = \mathbf{55.1\%}$$

Player C: $$TS\% = \frac{30}{2 \times (22 + 0.44 \times 8)} = \frac{30}{2 \times 25.52} = \frac{30}{51.04} = \mathbf{58.8\%}$$

Player D: $$TS\% = \frac{12}{2 \times (10 + 0.44 \times 4)} = \frac{12}{2 \times 11.76} = \frac{12}{23.52} = \mathbf{51.0\%}$$

Rankings by efficiency: 1. Player A: 60.6% 2. Player C: 58.8% 3. Player B: 55.1% 4. Player D: 51.0%

With league average TS% at 56.5%, Players A and C are above average, while B and D are below.


Exercise 6: VORP Calculation

Problem: Calculate VORP for players with given BPM and minutes.

Player BPM Minutes
A +8.0 3,000
B +5.0 2,500
C +3.0 3,200
D +1.0 2,000

Solution:

$$VORP = (BPM + 2.0) \times \frac{MP}{3936}$$

Where 3936 = 48 minutes x 82 games (a full season's minutes for one player position).

Player A: $$VORP = (8.0 + 2.0) \times \frac{3000}{3936} = 10.0 \times 0.762 = \mathbf{7.62}$$

Player B: $$VORP = (5.0 + 2.0) \times \frac{2500}{3936} = 7.0 \times 0.635 = \mathbf{4.45}$$

Player C: $$VORP = (3.0 + 2.0) \times \frac{3200}{3936} = 5.0 \times 0.813 = \mathbf{4.07}$$

Player D: $$VORP = (1.0 + 2.0) \times \frac{2000}{3936} = 3.0 \times 0.508 = \mathbf{1.52}$$

Rankings: 1. Player A: 7.62 VORP 2. Player B: 4.45 VORP 3. Player C: 4.07 VORP 4. Player D: 1.52 VORP

Key Insight: Player A dominates despite not having the most minutes because of their exceptional BPM. Player C plays the most minutes but ranks third in VORP due to lower rate of production. This illustrates the VORP formula's balance of rate (BPM) and volume (minutes).


Exercise 7: Rate vs. Volume

Problem: Compare Player X (BPM +9.0, 1,800 MIN) vs. Player Y (BPM +5.5, 3,100 MIN).

Solution:

a) Calculate VORP:

Player X: $VORP = (9.0 + 2.0) \times \frac{1800}{3936} = 11.0 \times 0.457 = \mathbf{5.03}$

Player Y: $VORP = (5.5 + 2.0) \times \frac{3100}{3936} = 7.5 \times 0.787 = \mathbf{5.90}$

b) Total value: Player Y provided more total value (5.90 vs. 5.03 VORP) despite lower per-minute impact.

c) Projected VORP at 3,000 minutes:

Player X: $(9.0 + 2.0) \times \frac{3000}{3936} = 11.0 \times 0.762 = 8.38$

Player Y: $(5.5 + 2.0) \times \frac{3000}{3936} = 7.5 \times 0.762 = 5.72$

If both could play 3,000 minutes, Player X would project to 8.38 VORP vs. Player Y's 5.72.

d) Tradeoffs: - Player X: Higher ceiling, more impactful per minute, but durability/availability concerns. Ideal as a high-impact starter or closer. - Player Y: More reliable availability, consistent production, but lower peak impact. Better for overall team stability.

Teams must balance: Is the best ability availability? Or is peak performance more valuable in critical moments?


Chapter 13: Win Shares and Wins Above Replacement

Exercise 3: Marginal Offense Calculation

Problem: Calculate marginal points per possession for a player with ORtg = 118, possessions = 1,500, when league average ORtg = 110.

Solution:

Marginal Points = (Player ORtg - League ORtg) x Possessions / 100

$$\text{Marginal Points} = (118 - 110) \times \frac{1500}{100} = 8 \times 15 = \mathbf{120 \text{ points}}$$

This player produced 120 more points than an average player would have in the same number of possessions.

To convert to wins (using ~30 points per win): $$\text{Wins Added} \approx \frac{120}{30} = \mathbf{4.0 \text{ wins}}$$


General Problem-Solving Strategies

For Calculation Problems

  1. Identify the formula needed from the chapter
  2. List all known values with their correct units
  3. Substitute carefully, checking each value
  4. Show intermediate steps for partial credit and error checking
  5. Verify reasonableness of the answer (e.g., percentages between 0-100%, positive game scores for good performances)

For Analysis Problems

  1. State your interpretation clearly
  2. Support with specific numbers from calculations
  3. Acknowledge limitations or alternative interpretations
  4. Connect to broader concepts from the chapter
  5. Consider context (era, team situation, player role)

Common Errors to Avoid

  • Confusing FGM (made) with FGA (attempted)
  • Forgetting to subtract player's own FGM for assist percentage
  • Using wrong denominators in percentage calculations
  • Not accounting for the 0.44 FTA multiplier in TS% and possession calculations
  • Mixing up team totals with individual stats

Additional solutions are available in the online course materials. Students are encouraged to work through problems independently before consulting solutions.